-
Notifications
You must be signed in to change notification settings - Fork 2
implement generic ROF model using Chambolle04 primal-dual method #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5a85f8e
to
7cb1af6
Compare
Codecov Report
@@ Coverage Diff @@
## master #24 +/- ##
==========================================
+ Coverage 92.07% 92.88% +0.81%
==========================================
Files 5 6 +1
Lines 227 253 +26
==========================================
+ Hits 209 235 +26
Misses 18 18
Continue to review full report at Codecov.
|
a86e651
to
2eea7af
Compare
This PR and #22 are specially written in a vectorized manner so that it also works for GPU arrays: using ImageBase
using ImageBase.Models
using TestImages
using Random
using CUDA
CUDA.allowscalar(false)
# 2d Gray
img = testimage("cameraman")
img_noisy = img .+ 0.1f0*randn(MersenneTwister(0), Float32, size(img))
@btime solve_ROF_PD($img_noisy, 0.2, 30);
# 101.396 ms (134 allocations: 134.00 MiB)
img_noisy_cu = CuArray(Float32.(img_noisy))
@btime solve_ROF_PD($img_noisy_cu, 0.2, 30); # GTX 3090
# 4.060 ms (8793 allocations: 754.84 KiB)
# 2d RGB
img = testimage("lighthouse")
img_noisy = img .+ colorview(RGB, ntuple(i->0.05.*randn(MersenneTwister(i), size(img)), 3)...)
@btime solve_ROF_PD($img_noisy, 0.2, 30);
# 610.880 ms (134 allocations: 597.00 MiB)
img_noisy_cu = CuArray(float32.(img_noisy))
@btime solve_ROF_PD($img_noisy_cu, 0.2, 30); # GTX 3090
# 7.176 ms (8433 allocations: 729.53 KiB) @timholy how do we test CUDA codes in JuliaImages? I have some special scripts in BlockMatching.jl to detect if Nvidia driver is installed, and if it is then it uses the CUDA package in the root environment and runs related tests. But since we don't have GPU servers we can't set up CI here. |
Also ping @JKay0327 since this PR takes a very similar spirit to what I and @timholy thought when we reviewed JuliaImages/ImageSegmentation.jl#84 |
About the code organization: in the near future I'm going to add the Split Bregman solver for the ROF model, which requires |
Nothing has been set up yet. We might want to ask the JuliaGPU folks what's involved in setting this up.
That sounds like a good idea to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. My main concern is whether this belongs here or in a more specialized package. I thought ImageBase
is supposed to have basic, widely-used algorithms. Or are you foreseeing using this widely across several other JuliaImages packages?
function solve_ROF_PD(img::AbstractArray, λ::Real, num_iters::Integer) | ||
# Total Variation regularized image denoising using the primal dual algorithm | ||
# Implement according to reference [1] | ||
τ = 1/4 # see 2nd remark after proof of Theorem 3.1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid forcing things to Float64
would it be better to just divide by 4 somewhere?
Mathematically, this function solves the following ROF model using the primal-dual method: | ||
|
||
```math | ||
\\min_u \\lVert u - g \\rVert^2 + \\lambda\\lvert\\nabla u\\rvert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have my fingers crossed for JuliaLang/julia#41915
412952e
to
0c8ffb7
Compare
From slack, it seems that we just need to apply https://github.com/JuliaGPU/buildkite. |
close in favor of JuliaImages/ImageFiltering.jl#233 |
Images.imROF
only supports 2D Gray image, with theRGB
image processed per channel. This version implements an RGB-native version (by fusing RGB into the inner calculation) and is also dimension-agnostic because of #22Comparison to
Images.imROF
:See the tests for 3d cases.
Todo: