Merging labels according to edge-to-edge-distances
In this notebook we will merge labels in a label image according to their edge-to-edge distances to each other. Labels close-by will be merged.
See also
For demonstration purposes, we use a modified version of the labels derived from the blobs example-image. We artificially introduce gaps between them.
|
cle._ image
shape | (254, 256) |
dtype | uint32 |
size | 254.0 kB |
min | 0.0 | max | 47.0 |
|
First, we dilate the labels by half of the maximum distance the edges are allowed to have.
|
cle._ image
shape | (254, 256) |
dtype | uint32 |
size | 254.0 kB |
min | 0.0 | max | 47.0 |
|
We then merge the labels if the touch.
|
cle._ image
shape | (254, 256) |
dtype | uint32 |
size | 254.0 kB |
min | 0.0 | max | 5.0 |
|
Afterwards, we mask the merged labels with the original label’s shape. We also convert the result of this operation to 32-bit integer, so that the visualization as label-image works.
|
cle._ image
shape | (254, 256) |
dtype | uint32 |
size | 254.0 kB |
min | 0.0 | max | 5.0 |
|