Add deblurring test using PDPS

Fri, 08 Jan 2021 16:09:09 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 08 Jan 2021 16:09:09 -0500
changeset 51
370931a692a1
parent 50
ef9d33ea4460
child 52
d2e28607c166

Add deblurring test using PDPS

README.md file | annotate | diff | comparison | revisions
Tests/src/Tests.jl file | annotate | diff | comparison | revisions
--- a/README.md	Fri Jan 08 15:54:35 2021 -0500
+++ b/README.md	Fri Jan 08 16:09:09 2021 -0500
@@ -50,4 +50,10 @@
 julia> test_denoise()
 ```
 
+To run a deblurring test using PDPS, continue with
+
+```console
+julia> test_deblur()
+```
+
   [AlgTools]: https://tuomov.iki.fi/software/AlgTools/
--- a/Tests/src/Tests.jl	Fri Jan 08 15:54:35 2021 -0500
+++ b/Tests/src/Tests.jl	Fri Jan 08 16:09:09 2021 -0500
@@ -5,7 +5,8 @@
 module Tests
 
 # Our exports
-export test_denoise, default_params
+export test_denoise,
+       test_deblur
 
 # Dependencies
 using Printf
@@ -20,19 +21,14 @@
 using AlgTools.LinkedLists
 using ImageTools.Denoise
 using ImageTools.Visualise
+using ImageTools.TVRecon
+using ImageTools.ImFilter
 
 # Parameters
-const default_save_prefix="denoise_result_"
+const default_save_prefix="result_"
 
 const default_params = (
-    α = 1,
-    # PDPS
-    # τ₀ = 5,
-    # σ₀ = 0.99/5,
-    # FISTA
-    τ₀ = 0.9,
     ρ = 0,
-    accel = true,
     noise_level = 0.5,
     verbose_iter = 10,
     maxiter = 1000,
@@ -41,19 +37,45 @@
     save_iterations = false
 )
 
-#######################
-# Main testing routine
-#######################
+const denoise_params = (
+    α = 2,
+    # FISTA
+    τ₀ = 0.9,
+    accel = true,
+)
+
+const deblur_params = (
+    α = 0.5,
+    # PDPS
+    τ₀ = 5,
+    σ₀ = 0.99/5,
+    accel = false,
+)
+
+function save_results(params, b, b_data, x)
+    if params.save_results
+        perffile = params.save_prefix * ".txt"
+        println("Saving " * perffile)
+        write_log(perffile, st.log, "# params = $(params)\n")
+        fn = (t, ext) -> "$(params.save_prefix)_$(t).$(ext)"
+        save(File(format"PNG", fn("true", "png")), grayimg(b))
+        save(File(format"PNG", fn("data", "png")), grayimg(b_data))
+        save(File(format"PNG", fn("reco", "png")), grayimg(x))
+    end
+end
+
+###############
+# Denoise test
+###############
 
 function test_denoise(;
                       visualise=true,
                       save_prefix=default_save_prefix,
                       kwargs...)
 
-    
     # Parameters for this experiment
-    params = default_params ⬿ kwargs
-    params = params ⬿ (save_prefix = save_prefix * params.image_name,)
+    params = default_params ⬿ denoise_params ⬿ kwargs
+    params = params ⬿ (save_prefix = save_prefix * "denoise_" * params.image_name,)
 
     # Load image and add noise
     b = Float64.(Gray{Float64}.(TestImages.testimage(params.image_name)))
@@ -65,15 +87,37 @@
     # Run algorithm
     x, y, st = denoise_fista(b_noisy; iterate=iterate, params=params)
 
-    if params.save_results
-        perffile = params.save_prefix * ".txt"
-        println("Saving " * perffile)
-        write_log(perffile, st.log, "# params = $(params)\n")
-        fn = (t, ext) -> "$(params.save_prefix)_$(t).$(ext)"
-        save(File(format"PNG", fn("true", "png")), grayimg(b))
-        save(File(format"PNG", fn("data", "png")), grayimg(b_noisy))
-        save(File(format"PNG", fn("reco", "png")), grayimg(x))
-    end
+    save_results(params, b, b_noisy, x)
+
+    # Exit background visualiser
+    finalise_visualisation(st)
+end
+
+##############
+# Deblur test
+##############
+
+function test_deblur(;
+                     visualise=true,
+                     save_prefix=default_save_prefix,
+                     kwargs...)
+
+    # Parameters for this experiment
+    params = default_params ⬿ deblur_params ⬿ kwargs
+    params = params ⬿ (save_prefix = save_prefix * "deblur_" * params.image_name,)
+
+    # Load image and add noise
+    b = Float64.(Gray{Float64}.(TestImages.testimage(params.image_name)))
+    op = FilterKernel(gaussian(2, [7,7]))
+    b_data = op(b .+ params.noise_level.*randn(size(b)...))
+
+    # Launch (background) visualiser
+    st, iterate = initialise_visualisation(visualise)
+
+    # Run algorithm
+    x, y, st = recon_pdps(b_data, op; xinit=zeros(size(b)...), iterate=iterate, params=params)
+
+    save_results(params, b, b_data, x)
 
     # Exit background visualiser
     finalise_visualisation(st)

mercurial