Skip to content

Commit d9cd260

Browse files
committed
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
1 parent 0bd7b31 commit d9cd260

File tree

5 files changed

+3
-63
lines changed

5 files changed

+3
-63
lines changed

Project.toml

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

src/Images.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export
8282
findlocalmaxima,
8383
findlocalminima,
8484
imgaussiannoise,
85-
imROF,
8685
otsu_threshold,
8786
yen_threshold,
8887

src/algorithms.jl

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

134-
"""
135-
```
136-
imgr = imROF(img, λ, iterations)
137-
```
138-
139-
Perform Rudin-Osher-Fatemi (ROF) filtering, more commonly known as Total
140-
Variation (TV) denoising or TV regularization. `λ` is the regularization
141-
coefficient for the derivative, and `iterations` is the number of relaxation
142-
iterations taken. 2d only.
143-
144-
See https://en.wikipedia.org/wiki/Total_variation_denoising and
145-
Chambolle, A. (2004). "An algorithm for total variation minimization and applications".
146-
Journal of Mathematical Imaging and Vision. 20: 89–97
147-
"""
148-
function imROF(img::AbstractMatrix{T}, λ::Number, iterations::Integer) where T<:NumberLike
149-
# Total Variation regularized image denoising using the primal dual algorithm
150-
# Also called Rudin Osher Fatemi (ROF) model
151-
# λ: regularization parameter
152-
s1, s2 = size(img)
153-
p = zeros(T, s1, s2, 2)
154-
# This iterates Eq. (9) of the Chambolle citation
155-
u = similar(img)
156-
τ = 1/4 # see 2nd remark after proof of Theorem 3.1.
157-
for i = 1:iterations
158-
div_p = ImageBase.FiniteDiff.fdiv(view(p, :, :, 1), view(p, :, :, 2))
159-
u .= img - λ*div_p # multiply term inside ∇ by -λ. Thm. 3.1 relates this to u via Eq. 7.
160-
grad_u = cat(ImageBase.fdiff(u, dims=1, boundary=:zero), ImageBase.fdiff(u, dims=2, boundary=:zero), dims=3)
161-
grad_u_mag = sqrt.(sum(abs2, grad_u, dims=3))
162-
p .= (p .-/λ).*grad_u)./(1 .+/λ).*grad_u_mag)
163-
end
164-
return u
165-
end
166-
167-
# ROF Model for color images
168-
function imROF(img::AbstractMatrix{<:Color}, λ::Number, iterations::Integer)
169-
out = similar(img)
170-
imgc = channelview(img)
171-
outc = channelview(out)
172-
for chan = 1:size(imgc, 1)
173-
outc[chan, :, :] = imROF(imgc[chan, :, :], λ, iterations)
174-
end
175-
out
176-
end
177134

178135
"""
179136
```

src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,3 +1146,5 @@ end
11461146
@deprecate boxdiff(Ai::IntegralArray{T,2}, tl_y::Integer, tl_x::Integer, br_y::Integer, br_x::Integer) where T Ai[tl_y..br_y, tl_x..br_x]
11471147

11481148
@deprecate div(A::AbstractArray{<:Any,3}) ImageBase.FiniteDiff.fdiv(view(A, :, :, 1), view(A, :, :, 2)) false
1149+
1150+
@deprecate imROF(img::AbstractMatrix, λ::Number, iterations::Integer) ImageFiltering.Models.solve_ROF_PD(img, λ, iterations)

test/algorithms.jl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,6 @@ using Test, Suppressor
248248
img = zeros(Gray{Float64},10,10,3)
249249
@test yen_threshold(img) == 0
250250
end
251-
252-
@testset "imROF" begin
253-
img = [0.1 0.2 0.1 0.8 0.9 0.7;
254-
0.2 0.1 0.1 0.8 0.1 0.8;
255-
0.1 0.2 0.1 0.7 0.9 0.8]
256-
# # Ground truth
257-
# using Optim
258-
# diff1(u) = [u[2:end,:]; u[end:end,:]] - u
259-
# diff2(u) = [u[:,2:end] u[:,end:end]] - u
260-
# obj(Avec, img, λ) = (A = reshape(Avec, size(img)); sum(abs2, A - img)/2 + λ*sum(sqrt.(diff1(A).^2 + diff2(A).^2)))
261-
# res = optimize(v->obj(v, img, 0.2), vec(img); iterations=10^4)
262-
# imgtv = reshape(res.minimizer, size(img))
263-
target = [fill(0.2, (3,3)) fill(0.656, (3,3))]
264-
@test all(map((x,y)->isapprox(x, y, atol=0.001), imROF(img, 0.2, 1000), target))
265-
imgc = colorview(RGB, img, img, img)
266-
targetc = colorview(RGB, target, target, target)
267-
@test all(map((x,y)->isapprox(x, y, atol=0.001), channelview(imROF(imgc, 0.2, 1000)), channelview(targetc)))
268-
end
269251
end
270252

271253
nothing

0 commit comments

Comments
 (0)