Sat, 04 Dec 2021 09:12:46 +0200
Update metadata to Julia 1.7 format
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 | |
50 | 5 | module Tests |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | |
43
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
7 | # Our exports |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
8 | export test_denoise, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
9 | test_deblur |
43
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
10 | |
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
11 | # Dependencies |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | using Printf |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
13 | using FileIO |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
14 | using ColorTypes: Gray |
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
15 | # 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
|
16 | # 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
|
17 | import ColorVectorSpace |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | import TestImages |
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 | using AlgTools.Util |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | using AlgTools.LinkedLists |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | using ImageTools.Denoise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | using ImageTools.Visualise |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
24 | using ImageTools.TVRecon |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
25 | using ImageTools.ImFilter |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | |
43
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
27 | # Parameters |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
28 | const default_save_prefix="result_" |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | const default_params = ( |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | ρ = 0, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | noise_level = 0.5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | verbose_iter = 10, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | maxiter = 1000, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | save_results = false, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | image_name = "lighthouse", |
25
1fba916f2b77
denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
37 | save_iterations = false |
9
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 | |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
40 | const denoise_params = ( |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
41 | α = 2, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
42 | # FISTA |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
43 | τ₀ = 0.9, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
44 | accel = true, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
45 | ) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
46 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
47 | const deblur_params = ( |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
48 | α = 0.5, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
49 | # PDPS |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
50 | τ₀ = 5, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
51 | σ₀ = 0.99/5, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
52 | accel = false, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
53 | ) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
54 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
55 | function save_results(params, b, b_data, x) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
56 | if params.save_results |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
57 | perffile = params.save_prefix * ".txt" |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
58 | println("Saving " * perffile) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
59 | write_log(perffile, st.log, "# params = $(params)\n") |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
60 | fn = (t, ext) -> "$(params.save_prefix)_$(t).$(ext)" |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
61 | save(File(format"PNG", fn("true", "png")), grayimg(b)) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
62 | save(File(format"PNG", fn("data", "png")), grayimg(b_data)) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
63 | save(File(format"PNG", fn("reco", "png")), grayimg(x)) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
64 | end |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
65 | end |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
66 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
67 | ############### |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
68 | # Denoise test |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
69 | ############### |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | function test_denoise(; |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
72 | visualise=true, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
73 | save_prefix=default_save_prefix, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
74 | kwargs...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
75 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
76 | # Parameters for this experiment |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
77 | params = default_params ⬿ denoise_params ⬿ kwargs |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
78 | params = params ⬿ (save_prefix = save_prefix * "denoise_" * params.image_name,) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
80 | # 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
|
81 | 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
|
82 | b_noisy = b .+ params.noise_level.*randn(size(b)...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | # Launch (background) visualiser |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
85 | st, iterate = initialise_visualisation(visualise) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | # Run algorithm |
28 | 88 | 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
|
89 | |
51
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
90 | save_results(params, b, b_noisy, x) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
91 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
92 | # Exit background visualiser |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
93 | finalise_visualisation(st) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
94 | end |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
95 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
96 | ############## |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
97 | # Deblur test |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
98 | ############## |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
99 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
100 | function test_deblur(; |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
101 | visualise=true, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
102 | save_prefix=default_save_prefix, |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
103 | kwargs...) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
104 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
105 | # Parameters for this experiment |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
106 | params = default_params ⬿ deblur_params ⬿ kwargs |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
107 | params = params ⬿ (save_prefix = save_prefix * "deblur_" * params.image_name,) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
108 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
109 | # Load image and add noise |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
110 | b = Float64.(Gray{Float64}.(TestImages.testimage(params.image_name))) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
111 | op = FilterKernel(gaussian(2, [7,7])) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
112 | b_data = op(b .+ params.noise_level.*randn(size(b)...)) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
113 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
114 | # Launch (background) visualiser |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
115 | st, iterate = initialise_visualisation(visualise) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
116 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
117 | # Run algorithm |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
118 | x, y, st = recon_pdps(b_data, op; xinit=zeros(size(b)...), iterate=iterate, params=params) |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
119 | |
370931a692a1
Add deblurring test using PDPS
Tuomo Valkonen <tuomov@iki.fi>
parents:
50
diff
changeset
|
120 | save_results(params, b, b_data, x) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
121 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
122 | # Exit background visualiser |
11
f1bbdf68f35b
Use Threads.@spawn instead of the broken hang-prone Distributed.
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
123 | finalise_visualisation(st) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
124 | end |
43
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
125 | |
492a57594b88
Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
126 | end |