|
1 ################## |
|
2 # Denoise testing |
|
3 ################## |
|
4 |
|
5 __precompile__() |
|
6 |
|
7 using Printf |
|
8 using Images |
|
9 import TestImages |
|
10 |
|
11 using AlgTools.Util |
|
12 using AlgTools.LinkedLists |
|
13 using ImageTools.Denoise |
|
14 using ImageTools.Visualise |
|
15 |
|
16 const default_save_prefix="denoise_result_" |
|
17 |
|
18 const default_params = ( |
|
19 α = 1, |
|
20 τ₀ = 5, |
|
21 σ₀ = 0.99/5, |
|
22 ρ = 0, |
|
23 accel = true, |
|
24 noise_level = 0.5, |
|
25 verbose_iter = 10, |
|
26 maxiter = 1000, |
|
27 save_results = false, |
|
28 save_iterations = false, |
|
29 image_name = "lighthouse", |
|
30 ) |
|
31 |
|
32 ####################### |
|
33 # Main testing routine |
|
34 ####################### |
|
35 |
|
36 function test_denoise(; |
|
37 visualise=true, |
|
38 save_prefix=default_save_prefix, |
|
39 kwargs...) |
|
40 |
|
41 |
|
42 # Parameters for this experiment |
|
43 params = default_params ⬿ kwargs |
|
44 params = params ⬿ (save_prefix = save_prefix * params.image_name,) |
|
45 |
|
46 # Load image and add noise |
|
47 b = Float64.(Gray.(TestImages.testimage(params.image_name))) |
|
48 b_noisy = b .+ params.noise_level.*randn(size(b)...) |
|
49 |
|
50 # Launch (background) visualiser |
|
51 st, iterate = initialise_visualisation(visualise) |
|
52 |
|
53 # Run algorithm |
|
54 x, y, st = denoise_pdps(b_noisy; iterate=iterate, params=params) |
|
55 |
|
56 if params.save_results |
|
57 perffile = params.save_prefix * ".txt" |
|
58 println("Saving " * perffile) |
|
59 write_log(perffile, st.log, "# params = $(params)\n") |
|
60 end |
|
61 |
|
62 # Exit background visualiser |
|
63 finish_visualisation(st) |
|
64 end |