Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not modify original image in in-place resizing #151

Merged
merged 10 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/resizing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
18 changes: 18 additions & 0 deletions test/resizing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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