image.distance_transform
What it is
No chapter describes this one yet. It exists -- the name comes from the interpreter's own table -- but the prose has not been written. That is a gap in the documentation, not in the engine.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
| no input | not documented yet | — |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
import image
# Two overlapping circles -- one connected blob to bwlabel.
w = 21
h = 13
mask_m = zeros(h, w)
for y in 0 to h - 1
for x in 0 to w - 1
in_a = (x - 6) ^ 2 + (y - 6) ^ 2 <= 25
in_b = (x - 14) ^ 2 + (y - 6) ^ 2 <= 25
if in_a or in_b
mask_m[y, x] = 255
end if
end for
end for
mask = image_from_matrix(mask_m)
n_blobs = bwlabel(mask).count
print(n_blobs) # 1 -- the two circles are one connected blob
dt = image.distance_transform(mask)
surface = -dt # each circle's own center floods first
markers = zeros(h, w)
markers[6, 6] = 1 # circle A's own center
markers[6, 14] = 2 # circle B's own center
labels = image.watershed(surface, markers=markers)
print(labels[6, 2]) # 1 -- deep inside circle A only
print(labels[6, 18]) # 2 -- deep inside circle B only
output
1 1 2
from images