Sat, 14 Dec 2019 14:59:59 +0200
Some threading
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 |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | using Images |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | import TestImages |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | using AlgTools.Util |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | using AlgTools.LinkedLists |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | using ImageTools.Denoise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | using ImageTools.Visualise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | const default_save_prefix="denoise_result_" |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | const default_params = ( |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | α = 1, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | τ₀ = 5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | σ₀ = 0.99/5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | ρ = 0, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | accel = true, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | noise_level = 0.5, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | verbose_iter = 10, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | maxiter = 1000, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | save_results = false, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | save_iterations = false, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | image_name = "lighthouse", |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | ) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | ####################### |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | # Main testing routine |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | ####################### |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | function test_denoise(; |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | visualise=true, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | save_prefix=default_save_prefix, |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | kwargs...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | |
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 | # Parameters for this experiment |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | params = default_params ⬿ kwargs |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | params = params ⬿ (save_prefix = save_prefix * params.image_name,) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | # Load image and add noise |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | b = Float64.(Gray.(TestImages.testimage(params.image_name))) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | b_noisy = b .+ params.noise_level.*randn(size(b)...) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
49 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | # Launch (background) visualiser |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 | st, iterate = initialise_visualisation(visualise) |
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 | # Run algorithm |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | x, y, st = denoise_pdps(b_noisy; iterate=iterate, params=params) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | if params.save_results |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | perffile = params.save_prefix * ".txt" |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | println("Saving " * perffile) |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
59 | write_log(perffile, st.log, "# params = $(params)\n") |
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | end |
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 | # Exit background visualiser |
11
f1bbdf68f35b
Use Threads.@spawn instead of the broken hang-prone Distributed.
Tuomo Valkonen <tuomov@iki.fi>
parents:
9
diff
changeset
|
63 | finalise_visualisation(st) |
9
1cffd3d07fe2
Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
64 | end |