Skip to content
Snippets Groups Projects
Commit 1962d312 authored by Stephan Hilb's avatar Stephan Hilb
Browse files

refactor

parent ef4e839a
Branches
Tags
No related merge requests found
...@@ -12,7 +12,7 @@ using Plots ...@@ -12,7 +12,7 @@ using Plots
using SemiSmoothNewton using SemiSmoothNewton
using SemiSmoothNewton: HMesh, ncells, refine, area, mesh_size, ndofs using SemiSmoothNewton: HMesh, ncells, refine, area, mesh_size, ndofs
using SemiSmoothNewton: project_img!, project_img2!, project! using SemiSmoothNewton: project_l2_lagrange!, project_qi_lagrange!, project!
using SemiSmoothNewton: vtk_mesh, vtk_append!, vtk_save using SemiSmoothNewton: vtk_mesh, vtk_append!, vtk_save
include("util.jl") include("util.jl")
...@@ -501,7 +501,7 @@ function denoise(img; name, params...) ...@@ -501,7 +501,7 @@ function denoise(img; name, params...)
ctx = L1L2TVContext(name, mesh, m; T, tdata = nothing, S, params...) ctx = L1L2TVContext(name, mesh, m; T, tdata = nothing, S, params...)
project_img!(ctx.g, img) project_l2_lagrange!(ctx.g, img)
#interpolate!(ctx.g, x -> evaluate_bilinear(img, x)) #interpolate!(ctx.g, x -> evaluate_bilinear(img, x))
#m = (size(img) .- 1) ./ 2 .+ 1 #m = (size(img) .- 1) ./ 2 .+ 1
#interpolate!(ctx.g, x -> norm(x .- m) < norm(m .- 1) / 3) #interpolate!(ctx.g, x -> norm(x .- m) < norm(m .- 1) / 3)
...@@ -538,7 +538,7 @@ function denoise(img; name, params...) ...@@ -538,7 +538,7 @@ function denoise(img; name, params...)
ctx, _ = refine(ctx, marked_cells) ctx, _ = refine(ctx, marked_cells)
test_mesh(ctx.mesh) test_mesh(ctx.mesh)
project_img!(ctx.g, img) project_l2_lagrange!(ctx.g, img)
k >= 100 && break k >= 100 && break
end end
...@@ -571,7 +571,7 @@ function denoise_pd(st, img; df=nothing, name, algorithm, params_...) ...@@ -571,7 +571,7 @@ function denoise_pd(st, img; df=nothing, name, algorithm, params_...)
sigma = inv(tau * L^2) sigma = inv(tau * L^2)
theta = 1. theta = 1.
#project_img!(st.g, img) #project_l2_lagrange!(st.g, img)
interpolate!(st.g, x -> evaluate_bilinear(img, x)) interpolate!(st.g, x -> evaluate_bilinear(img, x))
st.u.data .= st.g.data st.u.data .= st.g.data
...@@ -687,7 +687,7 @@ function denoise_approximation(ctx) ...@@ -687,7 +687,7 @@ function denoise_approximation(ctx)
ctx.params.alpha1, ctx.params.alpha2, ctx.params.lambda, ctx.params.beta, ctx.params.alpha1, ctx.params.alpha2, ctx.params.lambda, ctx.params.beta,
ctx.params.gamma1, ctx.params.gamma2) ctx.params.gamma1, ctx.params.gamma2)
#project_img!(st.g, img) #project_l2_lagrange!(st.g, img)
interpolate!(st.g, x -> evaluate_bilinear(ctx.params.img, x)) interpolate!(st.g, x -> evaluate_bilinear(ctx.params.img, x))
st.u.data .= st.g.data st.u.data .= st.g.data
#st.u.data .= rand(size(st.u.data)) #st.u.data .= rand(size(st.u.data))
...@@ -877,7 +877,7 @@ function optflow(ctx) ...@@ -877,7 +877,7 @@ function optflow(ctx)
function warp!() function warp!()
imgfw = warp_backwards(imgf1, sample(st.u)) imgfw = warp_backwards(imgf1, sample(st.u))
project_img!(fw, imgfw) project_l2_lagrange!(fw, imgfw)
# replace new tdata # replace new tdata
st = L1L2TVContext("run", mesh, st.d, st.m, T, nabla(fw), S, st = L1L2TVContext("run", mesh, st.d, st.m, T, nabla(fw), S,
...@@ -890,8 +890,8 @@ function optflow(ctx) ...@@ -890,8 +890,8 @@ function optflow(ctx)
end end
function reproject!() function reproject!()
project_img2!(f0, imgf0) project_qi_lagrange!(f0, imgf0)
project_img2!(f1, imgf1) project_qi_lagrange!(f1, imgf1)
end end
reproject!() reproject!()
warp!() warp!()
...@@ -988,13 +988,12 @@ function experiment_image_mesh_interpolation(ctx) ...@@ -988,13 +988,12 @@ function experiment_image_mesh_interpolation(ctx)
# all methods use bilinear interpolation for image evaluations # all methods use bilinear interpolation for image evaluations
methods = [ methods = [
#"nodal_interpolation" => interpolate!, "nodal" => interpolate!,
## techniques that use lagrange-lattice quadratures "l2_lagrange" => project_l2_lagrange!,
"l2_projection" => project_img!,
#"clement" => projec_clement!, #"clement" => projec_clement!,
"l1_stable_quasi_interpolation" => project_img2!, "qi_lagrange" => project_qi_lagrange!,
#"l1_stable_quasi_interpolation_avg" => project_img2!, #"qi_lagrange_avg" => project_qi_lagrange!,
#"l2_regression" => project_img_regression!, #"l2_pixel" => project_l2_pixel!,
] ]
map(methods) do (name, f) map(methods) do (name, f)
......
...@@ -135,10 +135,10 @@ end ...@@ -135,10 +135,10 @@ end
# TODO: refine interface: projection vs interpolation, unify different # TODO: refine interface: projection vs interpolation, unify different
# algorithms # algorithms
project_img(space::FeSpace, img) = project_l2_lagrange(space::FeSpace, img) =
(u = FeFunction(space); project_img!(u, img)) (u = FeFunction(space); project_l2_lagrange!(u, img))
function project_img!(u::FeFunction, img::AbstractArray) function project_l2_lagrange!(u::FeFunction, img::AbstractArray)
d = 2 # domain dimension d = 2 # domain dimension
space = u.space space = u.space
mesh = space.mesh mesh = space.mesh
...@@ -219,8 +219,8 @@ function project_img!(u::FeFunction, img::AbstractArray) ...@@ -219,8 +219,8 @@ function project_img!(u::FeFunction, img::AbstractArray)
return u return u
end end
project_img2(space::FeSpace, img) = project_qi_lagrange(space::FeSpace, img) =
(u = FeFunction(space); project_img2!(u, img)) (u = FeFunction(space); project_qi_lagrange!(u, img))
# L1-stable quasi-interpolation operator # L1-stable quasi-interpolation operator
# (https://arxiv.org/pdf/1505.06931.pdf) # (https://arxiv.org/pdf/1505.06931.pdf)
...@@ -228,7 +228,7 @@ project_img2(space::FeSpace, img) = ...@@ -228,7 +228,7 @@ project_img2(space::FeSpace, img) =
# FIXME: currently only approximate quadrature by sampling on lagrange lattice # FIXME: currently only approximate quadrature by sampling on lagrange lattice
# based on element size. Exact evaluation is tricky to implement (lots of # based on element size. Exact evaluation is tricky to implement (lots of
# intersection handling). # intersection handling).
function project_img2!(u::FeFunction, img) function project_qi_lagrange!(u::FeFunction, img)
u.space.element == P1() || u.space.element == P1() ||
throw(ArgumentError("element unsupported")) throw(ArgumentError("element unsupported"))
d = 2 # domain dimension d = 2 # domain dimension
...@@ -296,7 +296,7 @@ function quadrature_cell_pixels(mesh, cell; m0) ...@@ -296,7 +296,7 @@ function quadrature_cell_pixels(mesh, cell; m0)
end end
function interpolate_img_l2pixel!(u::FeFunction, img) function project_l2_pixel!(u::FeFunction, img)
d = 2 # domain dimension d = 2 # domain dimension
space = u.space space = u.space
mesh = space.mesh mesh = space.mesh
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment