DenoiseTest/src/DenoiseTest.jl

Fri, 08 Jan 2021 00:58:10 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 08 Jan 2021 00:58:10 -0500
changeset 48
1b9e90ca81e3
parent 43
492a57594b88
permissions
-rw-r--r--

Add FilterKernel LinOp

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
43
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
5 module DenoiseTest
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
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
8 export test_denoise, default_params
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
9
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
10 # Dependencies
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 using Printf
25
1fba916f2b77 denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents: 11
diff changeset
12 using FileIO
1fba916f2b77 denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents: 11
diff changeset
13 using ColorTypes: Gray
1fba916f2b77 denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents: 11
diff changeset
14 # 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
15 # 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
16 import ColorVectorSpace
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 import TestImages
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 using AlgTools.Util
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 using AlgTools.LinkedLists
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 using ImageTools.Denoise
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 using ImageTools.Visualise
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23
43
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
24 # Parameters
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 const default_save_prefix="denoise_result_"
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 const default_params = (
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 α = 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
29 # PDPS
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
30 # τ₀ = 5,
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
31 # σ₀ = 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
32 # FISTA
cfd989fa71c3 Fix denoise test script default parametrisation to be for FISTA instead of PDPS.
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
33 τ₀ = 0.9,
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 ρ = 0,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 accel = true,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 noise_level = 0.5,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 verbose_iter = 10,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 maxiter = 1000,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 save_results = false,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 image_name = "lighthouse",
25
1fba916f2b77 denoise test improvements: save results, don't depend on Images
Tuomo Valkonen <tuomov@iki.fi>
parents: 11
diff changeset
41 save_iterations = false
9
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
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 #######################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
45 # Main testing routine
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 #######################
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 function test_denoise(;
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 visualise=true,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 save_prefix=default_save_prefix,
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 kwargs...)
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
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 # Parameters for this experiment
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
55 params = default_params ⬿ kwargs
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56 params = params ⬿ (save_prefix = save_prefix * params.image_name,)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 # 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
59 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
60 b_noisy = b .+ params.noise_level.*randn(size(b)...)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 # Launch (background) visualiser
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 st, iterate = initialise_visualisation(visualise)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 # Run algorithm
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 25
diff changeset
66 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
67
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68 if params.save_results
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 perffile = params.save_prefix * ".txt"
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 println("Saving " * perffile)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71 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
72 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
73 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
74 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
75 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
76 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
78 # Exit background visualiser
11
f1bbdf68f35b Use Threads.@spawn instead of the broken hang-prone Distributed.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
79 finalise_visualisation(st)
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
80 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
81
492a57594b88 Make denoise test script a proper project so it can be run easily.
Tuomo Valkonen <tuomov@iki.fi>
parents: 42
diff changeset
82 end

mercurial