diff --git a/CHANGELOG.md b/CHANGELOG.md index f415393..a7cb307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,17 @@ # ImageTransformations +## Version `v0.9.3` + +- ![Bugfix][badge-bugfix] Do not modify original image when resizing. ([#151][github-151]) + ## Version `v0.9.2` -- ![Enhancement][badge-enhancement] The in-place version of resize function `imresize!` is optimized and exported. ([#150](github-150)) +- ![Enhancement][badge-enhancement] The in-place version of resize function `imresize!` is optimized and exported. ([#150][github-150]) ## Version `v0.9.1` - ![Enhancement][badge-enhancement] angles in `imrotate` are processed with high precision, restoring it to the same behavior you'd get from a manually-constructed - `tform` supplied to `warp`. This can change the presence/absence of padding on the edges. ([#148][github-148], [#149](github-149)) + `tform` supplied to `warp`. This can change the presence/absence of padding on the edges. ([#148][github-148], [#149][github-149]) ## Version `v0.9.0` @@ -29,7 +33,8 @@ whether a "fill-value" is used instead of interpolation. - ![Bugfix][badge-bugfix] `restrict` on `OffsetArray` always returns an `OffsetArray` result. ([ImageBase#4][github-base-4]) -[github-150]: https://github.com/JuliaImages/ImageTransformations.jl/pull/149 +[github-151]: https://github.com/JuliaImages/ImageTransformations.jl/pull/151 +[github-150]: https://github.com/JuliaImages/ImageTransformations.jl/pull/150 [github-149]: https://github.com/JuliaImages/ImageTransformations.jl/pull/149 [github-148]: https://github.com/JuliaImages/ImageTransformations.jl/pull/148 [github-143]: https://github.com/JuliaImages/ImageTransformations.jl/pull/143 diff --git a/src/resizing.jl b/src/resizing.jl index e5b58f6..fc84759 100644 --- a/src/resizing.jl +++ b/src/resizing.jl @@ -137,11 +137,11 @@ imresize_type(c) = typeof((c*1)/1) function imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}; method::Union{Interpolations.Degree,Interpolations.InterpolationType}=BSpline(Linear()), kwargs...) where {T,S,N} _imresize!(resized, original, method; kwargs...) end -function _imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}, method::Union{Interpolations.Degree, Interpolations.BSpline{D}}; kwargs...) where {T,S,N,D} +@inline function _imresize!(resized, original, method::Union{D, Interpolations.BSpline{D}}; kwargs...) where D <: Union{Constant, Linear} imresize!(resized, interpolate!(original, wrap_BSpline(method))) end -function _imresize!(resized::AbstractArray{T,N}, original::AbstractArray{S,N}, method::Interpolations.InterpolationType; kwargs...) where {T,S,N} - imresize!(resized, interpolate(original, method)) +@inline function _imresize!(resized, original, method; kwargs...) + imresize!(resized, interpolate(original, wrap_BSpline(method))) end function imresize!(resized::AbstractArray{T,N}, original::AbstractInterpolation{S,N}) where {T,S,N} diff --git a/test/resizing.jl b/test/resizing.jl index 5584d5b..649c569 100644 --- a/test/resizing.jl +++ b/test/resizing.jl @@ -180,4 +180,22 @@ end @test ref ≈ Gray.(out) end end + + @testset "In-place resizing should not modify original image" begin + for c in testcolor + image = rand(c, 128, 128) + original = copy(image) + out = zeros(eltype(image), 32, 32) + + methods = ( + Constant(), Linear(), + Quadratic(Reflect(OnCell())), + Quadratic(InPlace(OnCell())), + Cubic(Line(OnGrid())), Lanczos4OpenCV()) + for method in methods + imresize!(out, image, method=method) + @test image == original + end + end + end end