| |
1 ################## |
| |
2 # Denoise testing |
| |
3 ################## |
| |
4 |
| |
5 module Tests |
| |
6 |
| |
7 # Our exports |
| |
8 export test_denoise, default_params |
| |
9 |
| |
10 # Dependencies |
| |
11 using Printf |
| |
12 using FileIO |
| |
13 using ColorTypes: Gray |
| |
14 # ColorVectorSpace is only needed to ensure that conversions |
| |
15 # between different ColorTypes are defined. |
| |
16 import ColorVectorSpace |
| |
17 import TestImages |
| |
18 |
| |
19 using AlgTools.Util |
| |
20 using AlgTools.LinkedLists |
| |
21 using ImageTools.Denoise |
| |
22 using ImageTools.Visualise |
| |
23 |
| |
24 # Parameters |
| |
25 const default_save_prefix="denoise_result_" |
| |
26 |
| |
27 const default_params = ( |
| |
28 α = 1, |
| |
29 # PDPS |
| |
30 # τ₀ = 5, |
| |
31 # σ₀ = 0.99/5, |
| |
32 # FISTA |
| |
33 τ₀ = 0.9, |
| |
34 ρ = 0, |
| |
35 accel = true, |
| |
36 noise_level = 0.5, |
| |
37 verbose_iter = 10, |
| |
38 maxiter = 1000, |
| |
39 save_results = false, |
| |
40 image_name = "lighthouse", |
| |
41 save_iterations = false |
| |
42 ) |
| |
43 |
| |
44 ####################### |
| |
45 # Main testing routine |
| |
46 ####################### |
| |
47 |
| |
48 function test_denoise(; |
| |
49 visualise=true, |
| |
50 save_prefix=default_save_prefix, |
| |
51 kwargs...) |
| |
52 |
| |
53 |
| |
54 # Parameters for this experiment |
| |
55 params = default_params ⬿ kwargs |
| |
56 params = params ⬿ (save_prefix = save_prefix * params.image_name,) |
| |
57 |
| |
58 # Load image and add noise |
| |
59 b = Float64.(Gray{Float64}.(TestImages.testimage(params.image_name))) |
| |
60 b_noisy = b .+ params.noise_level.*randn(size(b)...) |
| |
61 |
| |
62 # Launch (background) visualiser |
| |
63 st, iterate = initialise_visualisation(visualise) |
| |
64 |
| |
65 # Run algorithm |
| |
66 x, y, st = denoise_fista(b_noisy; iterate=iterate, params=params) |
| |
67 |
| |
68 if params.save_results |
| |
69 perffile = params.save_prefix * ".txt" |
| |
70 println("Saving " * perffile) |
| |
71 write_log(perffile, st.log, "# params = $(params)\n") |
| |
72 fn = (t, ext) -> "$(params.save_prefix)_$(t).$(ext)" |
| |
73 save(File(format"PNG", fn("true", "png")), grayimg(b)) |
| |
74 save(File(format"PNG", fn("data", "png")), grayimg(b_noisy)) |
| |
75 save(File(format"PNG", fn("reco", "png")), grayimg(x)) |
| |
76 end |
| |
77 |
| |
78 # Exit background visualiser |
| |
79 finalise_visualisation(st) |
| |
80 end |
| |
81 |
| |
82 end |