How to use distance_transform in Images.jl


Tried to use

distance_transform(rand(Bool, 500, 500))

from Images.jl, but got

MethodError: no method matching distance_transform(::Array{Bool,2})
Closest candidates are:
  distance_transform(!Matched::AbstractArray{CartesianIndex{N},N}) where N at

Integer arrays also don’t work, the documentation site is down, so maybe someone knows what this function expects as input?


Try here:

using Images, ImageSegmentation

julia> img = load(download(""));

julia> bw = Gray.(img) .> 0.5;

julia> dist = 1 .- distance_transform(feature_transform(bw));

[NB I know absolutely nothing about Image analysis or Images.jl so have just copied the first example I could find]


Hi there!

I think you want to do something like this:

using Images, ImageView
A=rand(Bool, 500, 500)

The first function finds the closest pixel, the second one actually computes distance map transform (as you want it i guess). Works the same in 3D.
Hope this helps,