Skip to content

Commit

Permalink
Merge pull request #713 from JuliaImages/cs/imagedistances
Browse files Browse the repository at this point in the history
Migrate to and reexport ImageDistances.jl
  • Loading branch information
Evizero authored Apr 1, 2018
2 parents bffc92a + 326c0b3 commit f99e360
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 84 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ImageCore
ImageTransformations 0.2.2
ImageFiltering
ImageMorphology
ImageDistances 0.0.2
AxisArrays
ImageAxes
ImageMetadata
Expand Down
40 changes: 19 additions & 21 deletions src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const is_little_endian = ENDIAN_BOM == 0x04030201
@reexport using ImageMetadata
@reexport using ImageFiltering
@reexport using ImageMorphology
@reexport using ImageDistances

using ImageMetadata: ImageMetaAxis
import ImageMorphology: dilate, erode
Expand All @@ -71,40 +72,40 @@ struct Percentile{T} <: Real p::T end
HomogeneousPoint(x::NTuple{N, T})
In projective geometry [homogeneous coordinates](https://en.wikipedia.org/wiki/Homogeneous_coordinates) are the
natural coordinates for describing points and lines.
natural coordinates for describing points and lines.
For instance, the homogeneous coordinates for a planar point are a triplet of real numbers ``(u, v ,w)``, with ``w \\neq 0``.
This triple can be associated with a point ``P = (x,y)`` in Cartesian coordinates, where ``x = \\frac{u}{w}`` and ``y = \\frac{v}{w}``
For instance, the homogeneous coordinates for a planar point are a triplet of real numbers ``(u, v ,w)``, with ``w \\neq 0``.
This triple can be associated with a point ``P = (x,y)`` in Cartesian coordinates, where ``x = \\frac{u}{w}`` and ``y = \\frac{v}{w}``
[(more details)](http://www.geom.uiuc.edu/docs/reference/CRC-formulas/node6.html#SECTION01140000000000000000).
In particular, the `HomogeneousPoint((10.0,5.0,1.0))` is the standardised projective representation of the Cartesian
point `(10.0,5.0)`.
In particular, the `HomogeneousPoint((10.0,5.0,1.0))` is the standardised projective representation of the Cartesian
point `(10.0,5.0)`.
"""
struct HomogeneousPoint{T <: AbstractFloat,N}
struct HomogeneousPoint{T <: AbstractFloat,N}
coords::NTuple{N, T}
end

# By overwriting Base.to_indices we can define how to index into an N-dimensional array
# given an (N+1)-dimensional [`HomogeneousPoint`](@ref) type.
# given an (N+1)-dimensional [`HomogeneousPoint`](@ref) type.
# We do this by converting the homogeneous coordinates to Cartesian coordinates
# and rounding to nearest integer.
#
# For homogeneous coordinates of a planar point we return
# a tuple of permuted Cartesian coordinates, (y,x), since matrices
#
# For homogeneous coordinates of a planar point we return
# a tuple of permuted Cartesian coordinates, (y,x), since matrices
# are indexed according to row and then column.
# For homogeneous coordinates of other dimensions we do not permute
# the corresponding Cartesian coordinates.
# For homogeneous coordinates of other dimensions we do not permute
# the corresponding Cartesian coordinates.
Base.to_indices(A::AbstractArray, p::Tuple{<: HomogeneousPoint}) = homogeneous_point_to_indices(p[1])

function homogeneous_point_to_indices(p::HomogeneousPoint{T,3}) where T
function homogeneous_point_to_indices(p::HomogeneousPoint{T,3}) where T
if p.coords[end] == 1
return round(Int, p.coords[2]), round(Int, p.coords[1])
return round(Int, p.coords[2]), round(Int, p.coords[1])
else
return round(Int, p.coords[2] / p.coords[end]), round(Int, p.coords[1] / p.coords[end])
end
return round(Int, p.coords[2] / p.coords[end]), round(Int, p.coords[1] / p.coords[end])
end
end

function homogeneous_point_to_indices(p::HomogeneousPoint)
function homogeneous_point_to_indices(p::HomogeneousPoint)
if p.coords[end] == 1
return round.(Int, p.coords)
else
Expand All @@ -120,10 +121,10 @@ include("edge.jl")
include("showmime.jl")
include("juno.jl")
include("corner.jl")
include("distances.jl")
include("bwdist.jl")
using .FeatureTransform
include("convexhull.jl")
include("deprecated.jl")

export # types
BlobLoG,
Expand Down Expand Up @@ -267,9 +268,6 @@ export # types
bilinear_interpolation,
gaussian_pyramid,

# distances
hausdorff_distance,

# phantoms
shepp_logan

Expand Down
26 changes: 2 additions & 24 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
function canny(img_gray::AbstractMatrix{T}, sigma::Number = 1.4, upperThreshold::Number = 0.90, lowerThreshold::Number = 0.10; percentile::Bool = true) where T<:NumberLike
depwarn("canny(img, sigma, $upperThreshold, $lowerThreshold; percentile=$percentile) is deprecated.\n Please use canny(img, ($upperThreshold, $lowerThreshold), sigma) or canny(img, (Percentile($(100*upperThreshold)), Percentile($(100*lowerThreshold))), sigma)",:canny)
if percentile
canny(img_gray, (Percentile(100*upperThreshold), Percentile(100*lowerThreshold)), sigma)
else
canny(img_gray, (upperThreshold, lowerThreshold), sigma)
end
end
export hausdorff_distance

function imcorner(img::AbstractArray, threshold, percentile;
method::Function = harris, args...)
if percentile == true # NB old function didn't require Bool, this ensures conversion
depwarn("imcorner(img, $threshold, true; ...) is deprecated. Please use imcorner(img, Percentile($(100*threshold)); ...) instead.", :imcorner)
imcorner(img, Percentile(100*threshold); method=method, args...)
else
depwarn("imcorner(img, $threshold, false; ...) is deprecated. Please use imcorner(img, $threshold; ...) instead.", :imcorner)
imcorner(img, threshold; method=method, args...)
end
end

function imedge(img::AbstractArray, method::AbstractString, border::AbstractString="replicate")
f = ImageFiltering.kernelfunc_lookup(method)
depwarn("`imedge(img, \"$method\", args...)` is deprecated, please use `imedge(img, $f, args...)` instead.", :imedge)
imedge(img, f, border)
end
@deprecate hausdorff_distance(A,B) modified_hausdorff(A,B)
38 changes: 0 additions & 38 deletions src/distances.jl

This file was deleted.

2 changes: 2 additions & 0 deletions test/distances.jl → test/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Base.Test, Images

info("From this point on there will be deprectation warnings")

srand(2015)

@testset "Distances" begin
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include("exposure.jl")
include("edge.jl")
include("corner.jl")
include("bwdist.jl")
include("distances.jl")
include("writemime.jl")
include("deprecated.jl")

end

0 comments on commit f99e360

Please sign in to comment.