Skip to content

Commit

Permalink
Add autorange and warp tests for non-1 arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 11, 2017
1 parent 84a4757 commit 47afbe8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
julia 0.5
ImageCore 0.1.2
CoordinateTransformations 0.4.0
Interpolations 0.3.7
Interpolations 0.4
AxisAlgorithms
OffsetArrays
StaticArrays
Colors 0.7.0
Expand Down
2 changes: 1 addition & 1 deletion src/ImageTransformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ImageTransformations
using ImageCore
using CoordinateTransformations
using StaticArrays
using Interpolations
using Interpolations, AxisAlgorithms
using OffsetArrays
using FixedPointNumbers
using Colors, ColorVectorSpace
Expand Down
12 changes: 12 additions & 0 deletions src/warp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ function warp!(out, img::AbstractExtrapolation, tform)
end
out
end

# This is type-piracy, but necessary if we want Interpolations to be
# independent of OffsetArrays.
function AxisAlgorithms.A_ldiv_B_md!(dest::OffsetArray, F, src::OffsetArray, dim::Integer, b::AbstractVector)
indsdim = indices(parent(src), dim)
indsF = indices(F)[2]
if indsF == indsdim
AxisAlgorithms.A_ldiv_B_md!(parent(dest), F, parent(src), dim, b)
return dest
end
throw(DimensionMismatch("indices $(indices(parent(src))) do not match $(indices(F))"))
end
13 changes: 13 additions & 0 deletions test/autorange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,17 @@ end
@test rnge[2].stop == ceil(cos-ϕ)*d)
end
end
# Non-1 indices
for (indh, indw) in ((-1:10,0:20), (-1:20,-2:10), (0:7,-3:9))
h, w = length(indh), length(indw)
tst_img = OffsetArray(zeros(h,w), indh, indw)
for ϕ in deg2rad.(1:1:89)
rot = LinearMap(RotMatrix(ϕ))
rnge = @inferred ImageTransformations.autorange(tst_img, rot)
@test rnge[1].start == floor(cos(ϕ)*first(indh) - sin(ϕ)*last(indw))
@test rnge[1].stop == ceil(cos(ϕ)*last(indh) - sin(ϕ)*first(indw))
@test rnge[2].start == floor(sin(ϕ)*first(indh) + cos(ϕ)*first(indw))
@test rnge[2].stop == ceil(sin(ϕ)*last(indh) + cos(ϕ)*last(indw))
end
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ImageTransformations, CoordinateTransformations, TestImages, ImageCore, Colors, FixedPointNumbers
using ImageTransformations, CoordinateTransformations, TestImages, ImageCore, Colors, FixedPointNumbers, OffsetArrays, Interpolations
using Base.Test

tests = [
Expand Down
22 changes: 21 additions & 1 deletion test/warp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,25 @@ tfm = recenter(RotMatrix(-pi/4), center(img_pyramid))
imgr = warp(img_pyramid, tfm)
@test indices(imgr) == (0:6, 0:6)

# I do this very complicated because turns out NaNs are hard to compare...
# Use map and === because of the NaNs
@test all(map(===, round.(Float64.(parent(imgr)),3), round.(ref,3)))

img_pyramid_cntr = OffsetArray(img_pyramid, -2:2, -2:2)
tfm = LinearMap(RotMatrix(-pi/4))
imgr_cntr = warp(img_pyramid_cntr, tfm)
@test indices(imgr_cntr) == (-3:3, -3:3)
nearlysame(x, y) = x y || (isnan(x) & isnan(y))
@test all(map(nearlysame, parent(imgr_cntr), parent(imgr)))

itp = interpolate(img_pyramid_cntr, BSpline(Quadratic(Flat())), OnCell())
imgrq_cntr = warp(itp, tfm)
@test indices(imgrq_cntr) == (-3:3, -3:3)
refq = Float64[
NaN NaN NaN 0.003 NaN NaN NaN
NaN NaN -0.038 0.205 -0.038 NaN NaN
NaN -0.038 0.255 0.635 0.255 -0.038 NaN
0.003 0.205 0.635 1.0 0.635 0.205 0.003
NaN -0.038 0.255 0.635 0.255 -0.038 NaN
NaN NaN -0.038 0.205 -0.038 NaN NaN
NaN NaN NaN 0.003 NaN NaN NaN]
@test all(map(===, round.(Float64.(parent(imgrq_cntr)),3), round.(refq,3)))

0 comments on commit 47afbe8

Please sign in to comment.