Skip to content

Commit e7b2e05

Browse files
committed
[Images] 🧹 Deprecate imROF in favor of solve_ROF_PD
Because the boundary handling of divergence has changed, this is not an identical implementation of `imROF`. Thus old test codes are removed in this commit. Instead, ImageFiltering has more comprehensive test codes. See also: JuliaImages/ImageFiltering.jl#233 This commit bumps ImageFiltering compatibility to at least v0.7.1
1 parent 41d1d18 commit e7b2e05

File tree

5 files changed

+2
-63
lines changed

5 files changed

+2
-63
lines changed

packages/Images/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ImageBase = "0.1.5"
3737
ImageContrastAdjustment = "0.3.3"
3838
ImageCore = "0.9.3"
3939
ImageDistances = "0.2.5"
40-
ImageFiltering = "0.6.3"
40+
ImageFiltering = "0.7.1"
4141
ImageIO = "0.0.1, 0.3, 0.4, 0.5"
4242
ImageMagick = "0.7.5, 1"
4343
ImageMetadata = "0.9.7"

packages/Images/src/Images.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export
155155
findlocalminima,
156156
imgaussiannoise,
157157
imlineardiffusion,
158-
imROF,
159158
otsu_threshold,
160159
yen_threshold,
161160

packages/Images/src/algorithms.jl

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -301,49 +301,6 @@ end
301301
imgaussiannoise(img::AbstractArray{T}, variance::Number) where {T} = imgaussiannoise(img, variance, 0)
302302
imgaussiannoise(img::AbstractArray{T}) where {T} = imgaussiannoise(img, 0.01, 0)
303303

304-
"""
305-
```
306-
imgr = imROF(img, λ, iterations)
307-
```
308-
309-
Perform Rudin-Osher-Fatemi (ROF) filtering, more commonly known as Total
310-
Variation (TV) denoising or TV regularization. `λ` is the regularization
311-
coefficient for the derivative, and `iterations` is the number of relaxation
312-
iterations taken. 2d only.
313-
314-
See https://en.wikipedia.org/wiki/Total_variation_denoising and
315-
Chambolle, A. (2004). "An algorithm for total variation minimization and applications".
316-
Journal of Mathematical Imaging and Vision. 20: 89–97
317-
"""
318-
function imROF(img::AbstractMatrix{T}, λ::Number, iterations::Integer) where T<:NumberLike
319-
# Total Variation regularized image denoising using the primal dual algorithm
320-
# Also called Rudin Osher Fatemi (ROF) model
321-
# λ: regularization parameter
322-
s1, s2 = size(img)
323-
p = zeros(T, s1, s2, 2)
324-
# This iterates Eq. (9) of the Chambolle citation
325-
u = similar(img)
326-
τ = 1/4 # see 2nd remark after proof of Theorem 3.1.
327-
for i = 1:iterations
328-
div_p = ImageBase.FiniteDiff.fdiv(view(p, :, :, 1), view(p, :, :, 2))
329-
u .= img - λ*div_p # multiply term inside ∇ by -λ. Thm. 3.1 relates this to u via Eq. 7.
330-
grad_u = cat(ImageBase.fdiff(u, dims=1, boundary=:zero), ImageBase.fdiff(u, dims=2, boundary=:zero), dims=3)
331-
grad_u_mag = sqrt.(sum(abs2, grad_u, dims=3))
332-
p .= (p .-/λ).*grad_u)./(1 .+/λ).*grad_u_mag)
333-
end
334-
return u
335-
end
336-
337-
# ROF Model for color images
338-
function imROF(img::AbstractMatrix{<:Color}, λ::Number, iterations::Integer)
339-
out = similar(img)
340-
imgc = channelview(img)
341-
outc = channelview(out)
342-
for chan = 1:size(imgc, 1)
343-
outc[chan, :, :] = imROF(imgc[chan, :, :], λ, iterations)
344-
end
345-
out
346-
end
347304

348305
# morphological operations for ImageMeta
349306
dilate(img::ImageMeta, region=coords_spatial(img)) = shareproperties(img, dilate!(copy(arraydata(img)), region))

packages/Images/src/deprecations.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,7 @@ end
10811081
@deprecate backdiffx(X) ImageBase.FiniteDiff.fdiff(X, dims=2, rev=true, boundary=:zero)
10821082
@deprecate backdiffy(X) ImageBase.FiniteDiff.fdiff(X, dims=1, rev=true, boundary=:zero)
10831083
@deprecate div(A::AbstractArray{<:Any,3}) ImageBase.FiniteDiff.fdiv(view(A, :, :, 1), view(A, :, :, 2)) false
1084+
@deprecate imROF(img::AbstractMatrix, λ::Number, iterations::Integer) ImageFiltering.Models.solve_ROF_PD(img, λ, iterations)
10841085

10851086

10861087
# This is now replaced by ImageTransformations and Interpolations

packages/Images/test/algorithms.jl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -467,24 +467,6 @@ using ImageBase.FiniteDiff: fdiff
467467
img = zeros(Gray{Float64},10,10,3)
468468
@test yen_threshold(img) == 0
469469
end
470-
471-
@testset "imROF" begin
472-
img = [0.1 0.2 0.1 0.8 0.9 0.7;
473-
0.2 0.1 0.1 0.8 0.1 0.8;
474-
0.1 0.2 0.1 0.7 0.9 0.8]
475-
# # Ground truth
476-
# using Optim
477-
# diff1(u) = [u[2:end,:]; u[end:end,:]] - u
478-
# diff2(u) = [u[:,2:end] u[:,end:end]] - u
479-
# obj(Avec, img, λ) = (A = reshape(Avec, size(img)); sum(abs2, A - img)/2 + λ*sum(sqrt.(diff1(A).^2 + diff2(A).^2)))
480-
# res = optimize(v->obj(v, img, 0.2), vec(img); iterations=10^4)
481-
# imgtv = reshape(res.minimizer, size(img))
482-
target = [fill(0.2, (3,3)) fill(0.656, (3,3))]
483-
@test all(map((x,y)->isapprox(x, y, atol=0.001), imROF(img, 0.2, 1000), target))
484-
imgc = colorview(RGB, img, img, img)
485-
targetc = colorview(RGB, target, target, target)
486-
@test all(map((x,y)->isapprox(x, y, atol=0.001), channelview(imROF(imgc, 0.2, 1000)), channelview(targetc)))
487-
end
488470
end
489471

490472
nothing

0 commit comments

Comments
 (0)