# How to use distance\_transform in Images.jl

**URL:** <https://discourse.julialang.org/t/how-to-use-distance-transform-in-images-jl/18861>\
**Category:** Visualization\
**Created:** [December 20, 2018, 6:01pm UTC](https://discourse.julialang.org/t/how-to-use-distance-transform-in-images-jl/18861 "2018-12-20T18:01:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrgr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wrgr/32/2796_2.png) [@wrgr](https://discourse.julialang.org/u/wrgr)\
**Post date:** [December 20, 2018, 6:01pm UTC](https://discourse.julialang.org/t/how-to-use-distance-transform-in-images-jl/18861/1 "2018-12-20T18:01:05Z")

</div>

Tried to use

```julia
distance_transform(rand(Bool, 500, 500))

```

from `Images.jl`, but got

```julia
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?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 20, 2018, 7:42pm UTC](https://discourse.julialang.org/t/how-to-use-distance-transform-in-images-jl/18861/2 "2018-12-20T19:42:37Z")

</div>

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

```julia
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]

---

<div class="post-metadata">

**Author:** ![KirillGerke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kirillgerke/32/11383_2.png) [@KirillGerke](https://discourse.julialang.org/u/KirillGerke)\
**Post date:** [December 21, 2018, 8:21pm UTC](https://discourse.julialang.org/t/how-to-use-distance-transform-in-images-jl/18861/3 "2018-12-21T20:21:52Z")

</div>

Hi there!

I think you want to do something like this:

```julia
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
