Skip to content

Commit ec7696b

Browse files
committed
[Images] 🧹 Deprecate bilinear_interpolation in favor of imresize
I didn't do the archaeology but I believe this function existed long before we have Interpolations and ImageTransformations. Since we now have much much better support on these two packages, we won't need this legacy `bilinear_interpolation` method anymore.
1 parent 917b968 commit ec7696b

File tree

5 files changed

+42
-75
lines changed

5 files changed

+42
-75
lines changed

‎packages/Images/src/Images.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ export
186186
canny,
187187
integral_image,
188188
boxdiff,
189-
bilinear_interpolation,
190189
gaussian_pyramid,
191190

192191
# phantoms
@@ -219,7 +218,6 @@ Algorithms:
219218
- Blob detection: `blob_LoG`, `findlocalmaxima`, `findlocalminima`
220219
- Morphological operations: `dilate`, `erode`, `closing`, `opening`, `tophat`, `bothat`, `morphogradient`, `morpholaplace`, `feature_transform`, `distance_transform`, `convexhull`
221220
- Connected components: `label_components`, `component_boxes`, `component_lengths`, `component_indices`, `component_subscripts`, `component_centroids`
222-
- Interpolation: `bilinear_interpolation`
223221
224222
Test images and phantoms (see also TestImages.jl):
225223

‎packages/Images/src/algorithms.jl

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -447,47 +447,6 @@ function boxdiff(int_img::AbstractArray{T, 2}, tl_y::Integer, tl_x::Integer, br_
447447
sum
448448
end
449449

450-
"""
451-
```
452-
P = bilinear_interpolation(img, r, c)
453-
```
454-
455-
Bilinear Interpolation is used to interpolate functions of two variables
456-
on a rectilinear 2D grid.
457-
458-
The interpolation is done in one direction first and then the values obtained
459-
are used to do the interpolation in the second direction.
460-
461-
"""
462-
function bilinear_interpolation(img::AbstractArray{T, 2}, y::Number, x::Number) where T
463-
y_min = floor(Int, y)
464-
x_min = floor(Int, x)
465-
y_max = ceil(Int, y)
466-
x_max = ceil(Int, x)
467-
468-
topleft = chkbounds(Bool, img, y_min, x_min) ? img[y_min, x_min] : zero(T)
469-
bottomleft = chkbounds(Bool, img, y_max, x_min) ? img[y_max, x_min] : zero(T)
470-
topright = chkbounds(Bool, img, y_min, x_max) ? img[y_min, x_max] : zero(T)
471-
bottomright = chkbounds(Bool, img, y_max, x_max) ? img[y_max, x_max] : zero(T)
472-
473-
if x_max == x_min
474-
if y_max == y_min
475-
return T(topleft)
476-
end
477-
return T(((y_max - y) * topleft + (y - y_min) * bottomleft) / (y_max - y_min))
478-
elseif y_max == y_min
479-
return T(((x_max - x) * topleft + (x - x_min) * topright) / (x_max - x_min))
480-
end
481-
482-
r1 = ((x_max - x) * topleft + (x - x_min) * topright) / (x_max - x_min)
483-
r2 = ((x_max - x) * bottomleft + (x - x_min) * bottomright) / (x_max - x_min)
484-
485-
T(((y_max - y) * r1 + (y - y_min) * r2) / (y_max - y_min))
486-
487-
end
488-
489-
chkbounds(::Type{Bool}, img, x, y) = checkbounds(Bool, img, x, y)
490-
491450
"""
492451
```
493452
pyramid = gaussian_pyramid(img, n_scales, downsample, sigma)

‎packages/Images/src/deprecations.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,3 +1076,15 @@ function ColorVectorSpace.complement(x::AbstractArray)
10761076
complement.(x)
10771077
end
10781078

1079+
# This is now replaced by ImageTransformations and Interpolations
1080+
using ImageTransformations.Interpolations: BSpline, Linear, interpolate
1081+
function bilinear_interpolation(img::AbstractArray{T,N}, xs::Vararg{<:Number, N}) where {T,N}
1082+
Base.depwarn("`bilinear_interpolation` is deprecated, please use `warp`, `imresize` from ImageTransformations or `extrapolate`, `interpolate` from Interpolations", :bilinear_interpolation)
1083+
pad_ax = map(axes(img), xs) do ax, x
1084+
min(floor(Int, x), first(ax)):max(ceil(Int, x), last(ax))
1085+
end
1086+
padded_img = PaddedView(zero(T), img, pad_ax)
1087+
itp = interpolate(padded_img, BSpline(Linear()))
1088+
return itp(xs...)
1089+
end
1090+
export bilinear_interpolation

‎packages/Images/test/algorithms.jl

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -366,38 +366,6 @@ using Test, Suppressor
366366
@test eltype(img2) == RGB{Float32}
367367
end
368368

369-
@testset "Interpolations" begin
370-
371-
img = zeros(Float64, 5, 5)
372-
@test bilinear_interpolation(img, 4.5, 5.5) == 0.0
373-
@test bilinear_interpolation(img, 4.5, 3.5) == 0.0
374-
375-
for i in [1.0, 2.0, 5.0, 7.0, 9.0]
376-
img = ones(Float64, 5, 5) * i
377-
@test (bilinear_interpolation(img, 3.5, 4.5) == i)
378-
@test (bilinear_interpolation(img, 3.2, 4) == i) # X_MAX == X_MIN
379-
@test (bilinear_interpolation(img, 3.2, 4) == i) # Y_MAX == Y_MIN
380-
@test (bilinear_interpolation(img, 3.2, 4) == i) # BOTH EQUAL
381-
@test (bilinear_interpolation(img, 2.8, 1.9) == i)
382-
# One dim out of bounds
383-
@test isapprox(bilinear_interpolation(img, 0.5, 1.5), 0.5 * i)
384-
@test isapprox(bilinear_interpolation(img, 0.5, 1.6), 0.5 * i)
385-
@test isapprox(bilinear_interpolation(img, 0.5, 1.8), 0.5 * i)
386-
# Both out of bounds (corner)
387-
@test isapprox(bilinear_interpolation(img, 0.5, 0.5), 0.25 * i)
388-
end
389-
390-
img = reshape(1.0:1.0:25.0, 5, 5)
391-
@test bilinear_interpolation(img, 1.5, 2) == 6.5
392-
@test bilinear_interpolation(img, 2, 1.5) == 4.5
393-
@test bilinear_interpolation(img, 2, 1) == 2.0
394-
@test bilinear_interpolation(img, 1.5, 2.5) == 9.0
395-
@test bilinear_interpolation(img, 1.5, 3.5) == 14.0
396-
@test bilinear_interpolation(img, 1.5, 4.5) == 19.0
397-
@test bilinear_interpolation(img, 1.5, 5.5) == 10.75
398-
399-
end
400-
401369
@testset "Convex Hull" begin
402370
A = zeros(50, 30)
403371
A= convert(Array{Bool}, A)

‎packages/Images/test/deprecated.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,34 @@
1313
imgmeta = ImageMeta(imgcol, myprop=1)
1414
@test isa(restrict(imgmeta, [1, 2]), ImageMeta)
1515
end
16+
17+
@testset "Interpolations" begin
18+
img = zeros(Float64, 5, 5)
19+
@test bilinear_interpolation(img, 4.5, 5.5) == 0.0
20+
@test bilinear_interpolation(img, 4.5, 3.5) == 0.0
21+
22+
for i in [1.0, 2.0, 5.0, 7.0, 9.0]
23+
img = ones(Float64, 5, 5) * i
24+
@test (bilinear_interpolation(img, 3.5, 4.5) == i)
25+
@test (bilinear_interpolation(img, 3.2, 4) == i) # X_MAX == X_MIN
26+
@test (bilinear_interpolation(img, 3.2, 4) == i) # Y_MAX == Y_MIN
27+
@test (bilinear_interpolation(img, 3.2, 4) == i) # BOTH EQUAL
28+
@test (bilinear_interpolation(img, 2.8, 1.9) == i)
29+
# One dim out of bounds
30+
@test isapprox(bilinear_interpolation(img, 0.5, 1.5), 0.5 * i)
31+
@test isapprox(bilinear_interpolation(img, 0.5, 1.6), 0.5 * i)
32+
@test isapprox(bilinear_interpolation(img, 0.5, 1.8), 0.5 * i)
33+
# Both out of bounds (corner)
34+
@test isapprox(bilinear_interpolation(img, 0.5, 0.5), 0.25 * i)
35+
end
36+
37+
img = reshape(1.0:1.0:25.0, 5, 5)
38+
@test bilinear_interpolation(img, 1.5, 2) == 6.5
39+
@test bilinear_interpolation(img, 2, 1.5) == 4.5
40+
@test bilinear_interpolation(img, 2, 1) == 2.0
41+
@test bilinear_interpolation(img, 1.5, 2.5) == 9.0
42+
@test bilinear_interpolation(img, 1.5, 3.5) == 14.0
43+
@test bilinear_interpolation(img, 1.5, 4.5) == 19.0
44+
@test bilinear_interpolation(img, 1.5, 5.5) == 10.75
45+
end
1646
end

0 commit comments

Comments
 (0)