Skip to content

Commit e8f4bc5

Browse files
author
Anton Smirnov
authored
Do not modify original image when resizing (#151)
1 parent 6f2a65a commit e8f4bc5

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGELOG.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# ImageTransformations
22

3+
## Version `v0.9.3`
4+
5+
- ![Bugfix][badge-bugfix] Do not modify original image when resizing. ([#151][github-151])
6+
37
## Version `v0.9.2`
48

5-
- ![Enhancement][badge-enhancement] The in-place version of resize function `imresize!` is optimized and exported. ([#150](github-150))
9+
- ![Enhancement][badge-enhancement] The in-place version of resize function `imresize!` is optimized and exported. ([#150][github-150])
610

711
## Version `v0.9.1`
812

913
- ![Enhancement][badge-enhancement] angles in `imrotate` are processed with high precision, restoring it to the same behavior you'd get from a manually-constructed
10-
`tform` supplied to `warp`. This can change the presence/absence of padding on the edges. ([#148][github-148], [#149](github-149))
14+
`tform` supplied to `warp`. This can change the presence/absence of padding on the edges. ([#148][github-148], [#149][github-149])
1115

1216
## Version `v0.9.0`
1317

@@ -29,7 +33,8 @@ whether a "fill-value" is used instead of interpolation.
2933
- ![Bugfix][badge-bugfix] `restrict` on `OffsetArray` always returns an `OffsetArray` result. ([ImageBase#4][github-base-4])
3034

3135

32-
[github-150]: https://github.com/JuliaImages/ImageTransformations.jl/pull/149
36+
[github-151]: https://github.com/JuliaImages/ImageTransformations.jl/pull/151
37+
[github-150]: https://github.com/JuliaImages/ImageTransformations.jl/pull/150
3338
[github-149]: https://github.com/JuliaImages/ImageTransformations.jl/pull/149
3439
[github-148]: https://github.com/JuliaImages/ImageTransformations.jl/pull/148
3540
[github-143]: https://github.com/JuliaImages/ImageTransformations.jl/pull/143

src/resizing.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ imresize_type(c) = typeof((c*1)/1)
137137
function imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}; method::Union{Interpolations.Degree,Interpolations.InterpolationType}=BSpline(Linear()), kwargs...) where {T,S,N}
138138
_imresize!(resized, original, method; kwargs...)
139139
end
140-
function _imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}, method::Union{Interpolations.Degree, Interpolations.BSpline{D}}; kwargs...) where {T,S,N,D}
140+
@inline function _imresize!(resized, original, method::Union{D, Interpolations.BSpline{D}}; kwargs...) where D <: Union{Constant, Linear}
141141
imresize!(resized, interpolate!(original, wrap_BSpline(method)))
142142
end
143-
function _imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}, method::Interpolations.InterpolationType; kwargs...) where {T,S,N}
144-
imresize!(resized, interpolate(original, method))
143+
@inline function _imresize!(resized, original, method; kwargs...)
144+
imresize!(resized, interpolate(original, wrap_BSpline(method)))
145145
end
146146

147147
function imresize!(resized::AbstractArray{T,N}, original::AbstractInterpolation{S,N}) where {T,S,N}

test/resizing.jl

+18
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,22 @@ end
180180
@test ref Gray.(out)
181181
end
182182
end
183+
184+
@testset "In-place resizing should not modify original image" begin
185+
for c in testcolor
186+
image = rand(c, 128, 128)
187+
original = copy(image)
188+
out = zeros(eltype(image), 32, 32)
189+
190+
methods = (
191+
Constant(), Linear(),
192+
Quadratic(Reflect(OnCell())),
193+
Quadratic(InPlace(OnCell())),
194+
Cubic(Line(OnGrid())), Lanczos4OpenCV())
195+
for method in methods
196+
imresize!(out, image, method=method)
197+
@test image == original
198+
end
199+
end
200+
end
183201
end

0 commit comments

Comments
 (0)