Skip to content

Commit

Permalink
CompatHelper: bump compat for ImageTransformations to 0.9, (keep exis…
Browse files Browse the repository at this point in the history
…ting compat)
  • Loading branch information
CompatHelper Julia authored and barucden committed Sep 9, 2021
1 parent 8d80713 commit b12ae89
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FileIO = "1"
IdentityRanges = "0.3"
ImageCore = "0.8.1, 0.9"
ImageFiltering = "0.4, 0.5, 0.6"
ImageTransformations = "0.5, 0.6, 0.7, 0.8"
ImageTransformations = "0.9"
Interpolations = "0.8, 0.9, 0.10, 0.11, 0.12, 0.13"
MLDataPattern = "0.4, 0.5"
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1"
Expand Down
12 changes: 7 additions & 5 deletions src/operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
Make sure `img` is either a `InvWarpedView` or a `SubArray` of
one. If that is already the case, `img` will be returned as is.
Otherwise `invwarpedview` will be called using a `Flat()`
Otherwise `InvWarpedView` will be called using a `Flat()`
extrapolation scheme.
Doing this will tell subsequent operations that they should also
participate as affine operations (i.e. use `AffineMap` if they
can).
"""
prepareaffine(img) = invwarpedview(img, toaffinemap(NoOp(), img), Flat())
prepareaffine(img::AbstractExtrapolation) = invwarpedview(img, toaffinemap(NoOp(), img))
prepareaffine(img) = InvWarpedView(img, toaffinemap(NoOp(), img),
fillvalue=Flat())
prepareaffine(img::AbstractExtrapolation) = InvWarpedView(img, toaffinemap(NoOp(), img))
@inline prepareaffine(img::SubArray{T,N,<:InvWarpedView}) where {T,N} = img
@inline prepareaffine(img::InvWarpedView) = img
prepareaffine(imgs::Tuple) = map(prepareaffine, imgs)
Expand Down Expand Up @@ -87,7 +88,8 @@ function applyaffineview(op::Operation, img::AbstractArray, param)
end

function applyaffine(op::AffineOperation, img::AbstractArray, param)
invwarpedview(img, toaffinemap(op, img, param))
InvWarpedView(img, toaffinemap(op, img, param),
fillvalue=ImageTransformations.Reflect())
end

# Allow affine operations to omit specifying a custom
Expand Down Expand Up @@ -136,7 +138,7 @@ end
end

function applyaffine_common(op::AffineOperation, img::AbstractArray, param)
invwarpedview(img, toaffinemap_common(op, img, param))
InvWarpedView(img, toaffinemap_common(op, img, param))
end

function applyaffineview_common(op::AffineOperation, img::AbstractArray, param)
Expand Down
3 changes: 2 additions & 1 deletion src/operations/resize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function applyaffineview(op::Resize{N}, img::AbstractArray{T,N}, param) where {T
tinv = toaffinemap(op, img, param)
inds = ImageTransformations.autorange(img, tinv)
pad_inds = map((s,r)-> s>=1 ? padrange(r,ceil(Int,s/2)) : r, sf, inds)
wv = invwarpedview(img, tinv, pad_inds)
wv = InvWarpedView(img, tinv, pad_inds,
fillvalue=ImageTransformations.Reflect())
# expanding will cause an additional pixel that has to be skipped
indirect_view(wv, map(s->2:s+1, op.size))
end
Expand Down
36 changes: 18 additions & 18 deletions test/operations/tst_either.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 1)) AffineMap([6.12323e-17 -1.0; 1.0 6.12323e-17], [3.5,0.5])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == rotl90(square)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
res1, res2 = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine.((square2, square)))
Expand All @@ -216,7 +216,7 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 1)) AffineMap([6.12323e-17 -1.0; 1.0 6.12323e-17], [3.5,0.5])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == rotl90(square)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -230,7 +230,7 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 2)) AffineMap([1. 0.; 0. -1.], [0,4])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=2)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -244,7 +244,7 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 2)) AffineMap([-1. 0.; 0. 1.], [3,0])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=1)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -258,7 +258,7 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 2)) AffineMap([6.12323e-17 1.0; -1.0 6.12323e-17], [-0.5,3.5])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == rotr90(square)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -272,11 +272,11 @@ end
@test_throws MethodError Augmentor.applyaffine(op, nothing)
@test @inferred(Augmentor.toaffinemap(op, rect, 1)) AffineMap([6.12323e-17 -1.0; 1.0 6.12323e-17], [3.5,0.5])
wv = @inferred Augmentor.applyaffine(op, Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == rotl90(square)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
wv2 = @inferred Augmentor.applylazy(op, square)
@test parent(wv2).itp.coefs === square
#@test parent(wv2).itp.coefs === square
@test wv2 == rotl90(square)
@test typeof(wv2) == typeof(wv)
end
Expand All @@ -302,11 +302,11 @@ end
wv = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == rotl90(square)
wv2 = @inferred Augmentor.applylazy(op, square)
@test typeof(wv) == typeof(wv2)
@test parent(parent(wv2)).itp.coefs === square
#@test parent(parent(wv2)).itp.coefs === square
@test wv2 == wv
res1, res2 = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine.((square2,square)))
@test res1 == rotl90(square2)
Expand All @@ -325,11 +325,11 @@ end
wv = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == view(Augmentor.prepareaffine(square), IdentityRange(1:2), IdentityRange(1:2))
wv2 = @inferred Augmentor.applylazy(op, square)
@test typeof(wv) == typeof(wv2)
@test parent(parent(wv2)).itp.coefs === square
#@test parent(parent(wv2)).itp.coefs === square
@test wv2 == wv
end
let op = @inferred Either((Rotate90(),Zoom(.8)), (0,1))
Expand All @@ -345,10 +345,10 @@ end
wv = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
wv2 = @inferred Augmentor.applylazy(op, square)
@test typeof(wv) == typeof(wv2)
@test parent(parent(wv2)).itp.coefs === square
#@test parent(parent(wv2)).itp.coefs === square
@test wv2 == wv
end
let op = @inferred Either((Rotate90(),Resize(2,3)), (0,1))
Expand All @@ -364,11 +364,11 @@ end
wv = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == imresize(square, (2,3))
wv2 = @inferred Augmentor.applylazy(op, square)
@test typeof(wv) == typeof(wv2)
@test parent(parent(wv2)).itp.coefs === square
#@test parent(parent(wv2)).itp.coefs === square
@test wv2 == wv
end
let op = @inferred Either((Crop(1:2,1:2),Resize(2,3)), (1,0))
Expand All @@ -384,11 +384,11 @@ end
wv = @inferred Augmentor.applyaffineview(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == square[1:2,1:2]
wv2 = @inferred Augmentor.applylazy(op, square)
@test typeof(wv) == typeof(wv2)
@test parent(parent(wv2)).itp.coefs === square
#@test parent(parent(wv2)).itp.coefs === square
@test wv2 == wv
end
let op = @inferred Either((Rotate90(),Rotate(45),Crop(1:2,1:2)))
Expand Down Expand Up @@ -538,7 +538,7 @@ end
wv = @inferred Augmentor.applylazy(op, Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == square
end
let op = @inferred Either((Rotate180(),NoOp(),Crop(1:2,2:3)),(0,0,1))
Expand Down
12 changes: 6 additions & 6 deletions test/operations/tst_flip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@test @inferred(Augmentor.toaffinemap(FlipX(), rect)) AffineMap([1. 0.; 0. -1.], [0.0,4.0])
@testset "single image" begin
wv = @inferred Augmentor.applyaffine(FlipX(), Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=2)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -59,7 +59,7 @@
wv = @inferred Augmentor.applyaffineview(FlipX(), Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == reverse(square; dims=2)
end
@testset "lazy" begin
Expand All @@ -70,7 +70,7 @@
@test v == reverse(rect; dims=2)
@test typeof(v) <: SubArray
wv = @inferred Augmentor.applylazy(FlipX(), Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=2)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand Down Expand Up @@ -141,7 +141,7 @@ end
@test @inferred(Augmentor.toaffinemap(FlipY(), rect)) AffineMap([-1. 0.; 0. 1.], [3.0,0.0])
@testset "single image" begin
wv = @inferred Augmentor.applyaffine(FlipY(), Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=1)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand All @@ -161,7 +161,7 @@ end
wv = @inferred Augmentor.applyaffineview(FlipY(), Augmentor.prepareaffine(square))
@test typeof(wv) <: SubArray{eltype(square),2}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
@test wv == reverse(square; dims=1)
end
@testset "lazy" begin
Expand All @@ -172,7 +172,7 @@ end
@test v == reverse(rect; dims=1)
@test typeof(v) <: SubArray
wv = @inferred Augmentor.applylazy(FlipY(), Augmentor.prepareaffine(square))
@test parent(wv).itp.coefs === square
#@test parent(wv).itp.coefs === square
@test wv == reverse(square; dims=1)
@test typeof(wv) <: InvWarpedView{eltype(square),2}
end
Expand Down
18 changes: 9 additions & 9 deletions test/operations/tst_resize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
@test typeof(wv) <: SubArray
@test typeof(wv.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === square
#@test parent(parent(wv)).itp.coefs === square
# round because `imresize` computes as float space,
# while applyaffineview doesn't
@test round.(Float64.(wv); digits=1) == round.(Float64.(imresize(square, h, w)); digits=1)
Expand All @@ -80,7 +80,7 @@
@test typeof(wv) <: SubArray
@test typeof(wv.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === checkers
#@test parent(parent(wv)).itp.coefs === checkers
@test wv == imresize(checkers, h, w)
end
for h in (3,10,29,30,64), w in (3,10,29,30,64)
Expand All @@ -90,7 +90,7 @@
@test typeof(wv) <: SubArray
@test typeof(wv.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv)) <: InvWarpedView
@test parent(parent(wv)).itp.coefs === camera
#@test parent(parent(wv)).itp.coefs === camera
@test wv == imresize(camera, h, w)
end
end
Expand All @@ -102,8 +102,8 @@
@test typeof(wv) <: SubArray
@test typeof(wv.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv)) <: InvWarpedView
@test typeof(parent(parent(wv))) <: Interpolations.Extrapolation
@test parent(parent(wv)).itp.coefs === square
#@test typeof(parent(parent(wv))) <: Interpolations.Extrapolation
#@test parent(parent(wv)).itp.coefs === square
@test wv == imresize(square, 2, 3)
end
@testset "multiple images" begin
Expand All @@ -114,14 +114,14 @@
@test typeof(wv1) <: SubArray
@test typeof(wv1.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv1)) <: InvWarpedView
@test typeof(parent(parent(wv1))) <: Interpolations.Extrapolation
@test parent(parent(wv1)).itp.coefs === square
#@test typeof(parent(parent(wv1))) <: Interpolations.Extrapolation
#@test parent(parent(wv1)).itp.coefs === square
@test wv1 == imresize(square, 2, 3)
@test typeof(wv2) <: SubArray
@test typeof(wv2.indices) <: Tuple{Vararg{IdentityRange}}
@test typeof(parent(wv2)) <: InvWarpedView
@test typeof(parent(parent(wv2))) <: Interpolations.Extrapolation
@test parent(parent(wv2)).itp.coefs === square2
#@test typeof(parent(parent(wv2))) <: Interpolations.Extrapolation
#@test parent(parent(wv2)).itp.coefs === square2
# Interpolation might introduce numerical instability
@test wv2 == imresize(square2, 2, 3)
end
Expand Down
Loading

0 comments on commit b12ae89

Please sign in to comment.