Skip to content

Commit ad4053a

Browse files
authored
Merge pull request #148
Use higher precision in imrotate
2 parents 4d89e5c + 1ea801b commit ad4053a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ julia = "1"
2727

2828
[extras]
2929
EndpointRanges = "340492b5-2a47-5f55-813d-aca7ddf97656"
30+
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
3031
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
3132
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3233
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
3334
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3435
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
3536

3637
[targets]
37-
test = ["EndpointRanges", "ImageMagick", "LinearAlgebra", "ReferenceTests", "Test", "TestImages"]
38+
test = ["EndpointRanges", "ImageIO", "ImageMagick", "LinearAlgebra", "ReferenceTests", "Test", "TestImages"]

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)