# HG changeset patch # User Tuomo Valkonen # Date 1610140149 18000 # Node ID 370931a692a13e363e665f2d7429354e37aea22c # Parent ef9d33ea446073584c13008715bc658ed24ee1fd Add deblurring test using PDPS diff -r ef9d33ea4460 -r 370931a692a1 README.md --- 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/ diff -r ef9d33ea4460 -r 370931a692a1 Tests/src/Tests.jl --- 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)