Mon, 20 Apr 2020 12:04:11 -0500
Change README title
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | ################## |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | # Denoise testing |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | ################## |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | __precompile__() |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | using Printf |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
8 | using FileIO |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
9 | using ColorTypes: Gray |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
10 | # ColorVectorSpace is only needed to ensure that conversions |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
11 | # between different ColorTypes are defined. |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
12 | import ColorVectorSpace |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | import TestImages |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | using AlgTools.Util |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | using AlgTools.LinkedLists |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | using ImageTools.Denoise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | using ImageTools.Visualise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | const default_save_prefix="denoise_result_" |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | const default_params = ( |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | α = 1, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | τ₀ = 5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | σ₀ = 0.99/5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | ρ = 0, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | accel = true, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | noise_level = 0.5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | verbose_iter = 10, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | maxiter = 1000, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | save_results = false, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | image_name = "lighthouse", |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
33 | save_iterations = false |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | ) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | ####################### |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | # Main testing routine |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | ####################### |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | function test_denoise(; |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | visualise=true, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | save_prefix=default_save_prefix, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | kwargs...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | # Parameters for this experiment |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | params = default_params ⬿ kwargs |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | params = params ⬿ (save_prefix = save_prefix * params.image_name,) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
49 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | # Load image and add noise |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
51 | b = Float64.(Gray{Float64}.(TestImages.testimage(params.image_name))) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
52 | b_noisy = b .+ params.noise_level.*randn(size(b)...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | # Launch (background) visualiser |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | st, iterate = initialise_visualisation(visualise) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | # Run algorithm |
28 | 58 | x, y, st = denoise_fista(b_noisy; iterate=iterate, params=params) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
59 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | if params.save_results |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | perffile = params.save_prefix * ".txt" |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
62 | println("Saving " * perffile) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | write_log(perffile, st.log, "# params = $(params)\n") |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
64 | fn = (t, ext) -> "$(params.save_prefix)_$(t).$(ext)" |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
65 | save(File(format"PNG", fn("true", "png")), grayimg(b)) |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
66 | save(File(format"PNG", fn("data", "png")), grayimg(b_noisy)) |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
67 | save(File(format"PNG", fn("reco", "png")), grayimg(x)) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
68 | end |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | # Exit background visualiser |
11
f1bbdf68f35b
Use Threads.@spawn instead of the broken hang-prone Distributed.
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
71 | finalise_visualisation(st) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | end |