@@ -34,7 +34,6 @@ autorange(A, tform)
3434"""
3535autorange (A:: AbstractArray , tform) = autorange (CartesianIndices (A), tform)
3636function autorange (R:: CartesianIndices , tform)
37- tform = _round (tform)
3837 mn = mx = tform (SVector (first (R). I))
3938 for I in CornerIterator (R)
4039 x = tform (SVector (I. I))
@@ -46,7 +45,7 @@ function autorange(R::CartesianIndices, tform)
4645 _autorange (Tuple (mn), Tuple (mx))
4746end
4847
49- @noinline _autorange (mn,mx) = map ((a,b)-> floor (Int,a) : ceil (Int,b ), mn, mx)
48+ @noinline _autorange (mn,mx) = map ((a,b)-> floor (Int,_round (a)) : ceil (Int,_round (b) ), mn, mx)
5049
5150# # Iterate over the corner-indices of a rectangular region
5251struct CornerIterator{I<: CartesianIndex }
@@ -106,23 +105,13 @@ try_static(tfm::Translation{<:SVector}, img::AbstractArray{T,N}) where {T,N} = t
106105try_static (tfm:: Translation{<:AbstractVector} , img:: AbstractArray{T,N} ) where {T,N} =
107106 Translation (SVector {N} (tfm. translation))
108107
109- # Slightly round/discretize the transformation so that the warpped image size isn't affected by
108+ # Slightly round/discretize the output coordinates so that the warped image size isn't affected by
110109# numerical stability
111110# https://github.com/JuliaImages/ImageTransformations.jl/issues/104
112111_default_digits (:: Type{T} ) where T<: Number = _default_digits (floattype (T))
113112# these constants come from eps() digits
114- _default_digits (:: Type{<:AbstractFloat} ) = 15
115- _default_digits (:: Type{Float64} ) = 15
116- _default_digits (:: Type{Float32} ) = 7
113+ _default_digits (:: Type{T} ) where T <: AbstractFloat = ceil (Int, - log10 ( sqrt ( eps (T))))
114+ _default_digits (:: Type{Float64} ) = 8
115+ _default_digits (:: Type{Float32} ) = 4
117116
118- function _round (tform:: T ; kwargs... ) where T<: CoordinateTransformations.Transformation
119- rounded_fields = map (Base. OneTo (fieldcount (T))) do i
120- __round (getfield (tform, i); kwargs... )
121- end
122- T (rounded_fields... )
123- end
124- _round (tform; kwargs... ) = tform
125-
126- __round (x; kwargs... ) = x
127- __round (x:: AbstractArray ; digits= _default_digits (eltype (x)), kwargs... ) = round .(x; digits= digits, kwargs... )
128- __round (x:: T ; digits= _default_digits (T), kwargs... ) where T<: Number = round (x; digits= digits, kwargs... )
117+ _round (x:: T ; digits= _default_digits (T), kwargs... ) where T<: Number = round (x; digits= digits, kwargs... )
0 commit comments