From e4fe6a195b3f7e89eff53da43b0060455a55b488 Mon Sep 17 00:00:00 2001
From: Stephan Hilb <stephan@ecshi.net>
Date: Mon, 2 Oct 2023 10:29:37 +0200
Subject: [PATCH] fixup and cleanup

---
 scripts/run.jl             | 34 ++++++++--------------------------
 scripts/run_experiments.jl | 12 +++++++++---
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/scripts/run.jl b/scripts/run.jl
index 15b39f9..685725c 100644
--- a/scripts/run.jl
+++ b/scripts/run.jl
@@ -1,30 +1,11 @@
 include("run_experiments.jl")
 
-const datapath = joinpath(@__DIR__, "..", "data")
-const outpath = joinpath(@__DIR__, "..", "..", "data")
+const datapath = joinpath(@__DIR__, "../../data")
+const outpath = joinpath(@__DIR__, "../../data")
 
 ctx = Util.Context(datapath, outpath)
 
-# convergence
-
-# algorithm comparison
-#ctx(experiment_convergence_rate, "fem/convergence/rate")
-
-
-# adaptivity
-
-# residual estimator, discrete g, good
-# pd est, L2-TV, discrete g, good?
-# pd est, zero
-# pd est, L1-TV, bad
-
-
-# misc experiments
-
-# inpainting (OLD)
-#ctx(experiment_inpaint, "fem/inpaint")
-# adaptive optical flow
-#ctx(experiment_optflow_middlebury_all, "fem/optflow/middlebury")
+# NOTE: make sure middlebury data is available in each of the directories!
 
 function paper1(ctx)
     # newton vs other algs
@@ -33,12 +14,13 @@ function paper1(ctx)
     ctx(experiment_denoise, "fem/denoise")
     # combined inpainting + denoising with mixed noise
     ctx(experiment_inpaint_denoise, "fem/inpaint_denoise")
-
-    # comparison: warping and adaptivity
+    # comparison: vanilla / warping
     ctx(experiment_optflow_middlebury_warping_comparison, "fem/opticalflow/middlebury_warping_comparison")
 end
 
 function paper2(ctx)
-    # comparison: warping and adaptivity
-    ctx(experiment_optflow_middlebury_warping_comparison_adaptive, "fem/opticalflow/middlebury_warping_comparison")
+    # comparison: image mesh interpolation methods
+    ctx(experiment_image_mesh_interpolation, "image-mesh-interpolation")
+    # comparison: vanilla / warping / adaptive
+    ctx(experiment_optflow_middlebury_warping_comparison_adaptive, "fem/opticalflow/middlebury_warping_comparison_adaptive")
 end
diff --git a/scripts/run_experiments.jl b/scripts/run_experiments.jl
index e8527f4..bfd755b 100644
--- a/scripts/run_experiments.jl
+++ b/scripts/run_experiments.jl
@@ -1512,7 +1512,8 @@ function optflow(ctx)
     project_image!(f, img) =
         ctx.params.n_refine == 0 ?
             interpolate!(f, x -> evaluate_bilinear(img, x)) : # fine mesh
-            project_l2_lagrange! # coarse adaptive mesh
+            project_l2_lagrange!(f, img) # coarse adaptive mesh
+
 
     eps_newton = 1e-3 # cauchy criterion for inner newton loop
     eps_warp = 0.05
@@ -1529,6 +1530,10 @@ function optflow(ctx)
     f0 = FeFunction(Vg, name = "f0")
     f1 = FeFunction(Vg, name = "f1")
     fw = FeFunction(Vg, name = "fw")
+    # initialized later
+    f0.data .= NaN
+    f1.data .= NaN
+    fw.data .= NaN
 
     st = OptFlowState(mesh;
         ctx.params.alpha1, ctx.params.alpha2,
@@ -1537,6 +1542,7 @@ function optflow(ctx)
 
     function warp!()
         println("warp and reproject ...")
+
         # warp image into imgfw / fw
         imgfw = warp_backwards(imgf1, sample(st.u))
         project_image!(fw, imgfw)
@@ -1671,7 +1677,6 @@ end
 function experiment_optflow_middlebury_all_benchmarks(ctx)
     for example in ["Dimetrodon", "Grove2", "Grove3", "Hydrangea",
             "RubberWhale", "Urban2", "Urban3", "Venus"]
-        #example == "Dimetrodon" && continue
         ctx(experiment_optflow_middlebury, example;
             alpha1 = 10., alpha2 = 0., lambda = 1., beta = 1e-5,
             gamma1 = 1e-4, gamma2 = 1e-4, Schoice = :nabla, newton_max_iters = 30)
@@ -1781,7 +1786,8 @@ function experiment_image_mesh_interpolation(ctx)
             save_csv(joinpath(ctx.outdir, "$(mesh_size)_$(method).csv"), u)
 
             imgu = sample(u)
-            saveimg(joinpath(ctx.outdir, "$(mesh_size)_$(method).png"), to_img(imgu))
+            clamp01 = x -> clamp(x, 0., 1.)
+            saveimg(joinpath(ctx.outdir, "$(mesh_size)_$(method).png"), map(clamp01, to_img(imgu)))
 
             return method => (
                 psnr = assess_psnr(imgu, imgf),
-- 
GitLab