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