Skip to content

Commit 0160b84

Browse files
committed
Use higher precision in imrotate
Fixes #147
1 parent 4d89e5c commit 0160b84

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/warp.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ mosaicview([imgr for _ in 1:9]; nrow=3)
244244
"""
245245
function imrotate(img::AbstractArray{T}, θ::Real, inds::Union{Tuple, Nothing} = nothing; kwargs...) where T
246246
# TODO: expose rotation center as a keyword
247-
θ = floor(mod(θ,2pi)*typemax(Int16))/typemax(Int16) # periodic discretezation
247+
Δ = eps(θ)
248+
θ = mod2pi(θ)
249+
if abs(θ) <= Δ || abs- 2π) <= Δ
250+
θ = zero(θ)
251+
end
248252
tform = recenter(RotMatrix{2}(θ), center(img))
249253
# Use the `nothing` trick here because moving the `autorange` as default value is not type-stable
250254
inds = isnothing(inds) ? autorange(img, inv(tform)) : inds

test/warp.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ img_camera = testimage("camera")
268268
img = similar(img_camera)
269269
v = view(img, 75:195, 245:370)
270270
v .= view(img_camera, v.indices...)
271-
271+
272272
wv = InvWarpedView(v, tfm)
273273
@test wv isa InvWarpedView
274274
@test parent(wv) == v
275275
@test axes(wv) == (-78:82, 72:234)
276276
# boundaries are filled with 0 values
277-
@test all(wv[first(axes(wv, 1)), :] .== 0)
277+
@test all(wv[first(axes(wv, 1)), :] .== 0)
278278
@test all(wv[last(axes(wv, 1)), :] .== 0)
279279
@test all(wv[:, first(axes(wv, 2))] .== 0)
280280
@test all(wv[:, last(axes(wv, 2))] .== 0)
@@ -453,5 +453,17 @@ NaN NaN NaN NaN NaN NaN NaN
453453
end
454454
end
455455
end
456+
457+
@testset "issue #147" begin
458+
img = Float64[1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
459+
trfm = recenter(RotMatrix(pi/2), center(img))
460+
@test imrotate(img, π/2) warp(img, trfm) rotr90(img)
461+
@test any(isnan, imrotate(img, π/3))
462+
@test !any(isnan, imrotate(img, π/3; fillvalue=0.0))
463+
@test !any(isnan, imrotate(img, π/3, fillvalue=0.0))
464+
@test any(isnan, imrotate(img, π/3, axes(img)))
465+
@test !any(isnan, imrotate(img, π/3, axes(img); fillvalue=0.0))
466+
@test !any(isnan, imrotate(img, π/3, axes(img), fillvalue=0.0))
467+
end
456468
end
457469
end

0 commit comments

Comments
 (0)