From 59cdd730b8742e91395c22cf6ce228a58b6c8ee4 Mon Sep 17 00:00:00 2001
From: Stephan Hilb <stephan@ecshi.net>
Date: Mon, 6 Dec 2021 18:47:03 +0100
Subject: [PATCH] refactor

---
 scripts/run_experiments.jl |  6 +++---
 src/image.jl               | 17 ++++++++++-------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/scripts/run_experiments.jl b/scripts/run_experiments.jl
index 321fee6..f12db0f 100644
--- a/scripts/run_experiments.jl
+++ b/scripts/run_experiments.jl
@@ -502,7 +502,7 @@ function denoise(img; name, params...)
     ctx = L1L2TVContext(name, mesh, m; T, tdata = nothing, S, params...)
 
     project_img!(ctx.g, img)
-    #interpolate!(ctx.g, x -> interpolate_bilinear(img, x))
+    #interpolate!(ctx.g, x -> evaluate_bilinear(img, x))
     #m = (size(img) .- 1) ./ 2 .+ 1
     #interpolate!(ctx.g, x -> norm(x .- m) < norm(m .- 1) / 3)
 
@@ -572,7 +572,7 @@ function denoise_pd(st, img; df=nothing, name, algorithm, params_...)
     theta = 1.
 
     #project_img!(st.g, img)
-    interpolate!(st.g, x -> interpolate_bilinear(img, x))
+    interpolate!(st.g, x -> evaluate_bilinear(img, x))
     st.u.data .= st.g.data
 
     save_denoise(st, i) =
@@ -688,7 +688,7 @@ function denoise_approximation(ctx)
         ctx.params.gamma1, ctx.params.gamma2)
 
     #project_img!(st.g, img)
-    interpolate!(st.g, x -> interpolate_bilinear(ctx.params.img, x))
+    interpolate!(st.g, x -> evaluate_bilinear(ctx.params.img, x))
     st.u.data .= st.g.data
     #st.u.data .= rand(size(st.u.data))
 
diff --git a/src/image.jl b/src/image.jl
index dfab9b8..d0d1b33 100644
--- a/src/image.jl
+++ b/src/image.jl
@@ -1,4 +1,4 @@
-export interpolate_bilinear, halve, warp_backwards
+export evaluate_bilinear, halve, warp_backwards
 
 # ImageFunction
 
@@ -16,7 +16,7 @@ bind!(f::ImageFunction, cell) = f.cell[] = cell
 # transform coordinates to image/matrix indexing space
 img_coord(img, x) = (size(img, 1) - x[2] + 1, x[1])
 evaluate(f::ImageFunction, xloc) =
-    interpolate_bilinear(f.img,
+    evaluate_bilinear(f.img,
         img_coord(f.img, elmap(f.mesh, f.cell[])(xloc)))
 
 # FIXME: unused?
@@ -25,7 +25,7 @@ from_img(img) = permutedims(reverse(arr; dims = 1))
 eval_neumann(img, x) = img[clamp.(Tuple(x), axes(img))...]
 
 # uses native array indexing, i.e. 1:n
-function interpolate_bilinear(img, x)
+function evaluate_bilinear(img, x)
     x0 = floor.(Int, x)
     x1 = x0 .+ 1
 
@@ -47,7 +47,7 @@ function warp_backwards(img, u)
     res = similar(img)
     for I in CartesianIndices(img)
 	x = Tuple(I) .+ ntuple(i -> u[i, I], d)
-	res[I] = interpolate_bilinear(img, x)
+	res[I] = evaluate_bilinear(img, x)
     end
     return res
 end
@@ -125,17 +125,20 @@ end
 
 """
 interprets `img` as a bilinearly interpolated continuous function and applies
-the default interpolation function for the discrete function u.
+the default interpolation operator for the discrete function u.
 """
-function interpolate!(u, img)
+function interpolate!(u::FeFunction, img::AbstractArray)
     f = ImageFunction(u.space.mesh, img)
     interpolate!(u, @inline (x; f) -> f; f)
 end
 
+# TODO: refine interface: projection vs interpolation, unify different
+# algorithms
+
 project_img(space::FeSpace, img) =
     (u = FeFunction(space); project_img!(u, img))
 
-function project_img!(u::FeFunction, img)
+function project_img!(u::FeFunction, img::AbstractArray)
     d = 2 # domain dimension
     space = u.space
     mesh = space.mesh
-- 
GitLab