test/denoise.jl

Tue, 25 Aug 2020 13:53:17 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 25 Aug 2020 13:53:17 +0300
changeset 42
cfd989fa71c3
parent 28
d1f40f6654cb
permissions
-rw-r--r--

Fix denoise test script default parametrisation to be for FISTA instead of PDPS.

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,
42
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
24 # PDPS
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
25 # τ₀ = 5,
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
26 # σ₀ = 0.99/5,
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
27 # FISTA
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
28 τ₀ = 0.9,
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 ρ = 0,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 accel = true,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 noise_level = 0.5,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 verbose_iter = 10,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 maxiter = 1000,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 save_results = false,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 image_name = "lighthouse",
25
1fba916f2b77 denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents: 11
diff changeset
36 save_iterations = false
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 )
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 # Main testing routine
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 #######################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43 function test_denoise(;
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 visualise=true,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
45 save_prefix=default_save_prefix,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 kwargs...)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 # Parameters for this experiment
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 params = default_params ⬿ kwargs
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 params = params ⬿ (save_prefix = save_prefix * params.image_name,)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 # 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
54 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
55 b_noisy = b .+ params.noise_level.*randn(size(b)...)
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 # Launch (background) visualiser
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 st, iterate = initialise_visualisation(visualise)
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 # Run algorithm
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 25
diff changeset
61 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
62
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 if params.save_results
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 perffile = params.save_prefix * ".txt"
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 println("Saving " * perffile)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 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
67 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
68 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
69 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
70 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
71 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 # Exit background visualiser
11
f1bbdf68f35b Use Threads.@spawn instead of the broken hang-prone Distributed.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
74 finalise_visualisation(st)
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75 end

mercurial