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: https://webcache.googleusercontent.com/search?q=cache:yeGsE8wyDJQJ:https://juliaimages.github.io/latest/imagesegmentation.html+&cd=4&hl=en&ct=clnk&gl=uk

using Images, ImageSegmentation

julia> img = load(download("http://docs.opencv.org/3.1.0/water_coins.jpg"));

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]

1 Like

Hi there!

I think you want to do something like this:

using Images, ImageView
A=rand(Bool, 500, 500)
B=feature_transform(A)
C=distance_transform(B)
imshow(C)

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,
Kirill

2 Likes