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 8 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
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