digitopo.watershed
¶
Topological watershed of grey-level images (2D and 3D).
The functions, parameters and results are those of pink26.watershed.
Think of a grey-level image as a relief: dark points are low, bright points
are high. The lower section at level k is the set of the points below
k; its connected components are the lakes at level k. The
topological watershed lowers the image as much as possible without ever
merging two lakes, creating one or making one disappear, at any level. The
minima then fill their basins, and what is left between the basins are thin
crest lines, at the level of the passes between the minima.
connectivity is the adjacency of the lakes, the basins and the minima: 4
or 8 in 2D, 6, 18 or 26 in 3D. The image has no frame: a minimum that
touches the side of the image is a minimum like any other.
References
M. Couprie, G. Bertrand, "Topological gray-scale watershed transformation", Proc. SPIE Vision Geometry VI, vol. 3168, 1997, pp. 136-146.
G. Bertrand, "On topological watersheds", Journal of Mathematical Imaging and Vision 22(2-3), 2005, pp. 217-230.
M. Couprie, L. Najman, G. Bertrand, "Quasi-linear algorithms for the topological watershed", Journal of Mathematical Imaging and Vision 22(2-3), 2005, pp. 231-249.
topological_watershed
¶
topological_watershed(
image: ArrayLike,
connectivity: int,
*,
convert: bool = False,
) -> NDArray[np.uint8]
Lower a grey-level image to its topological watershed.
Lowers W-destructible points until none is left. The result is a new
uint8 array, at most image at every point, with the same number
of lakes at every level, the same minima and the same level of passes.
On a plateau, the place of a crest line depends on the order in which
the points are visited (Pink's order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D |
required |
connectivity
|
int
|
Connectivity of the minima and basins: 4 or 8 in 2D, 6, 18 or 26 in 3D. |
required |
convert
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If the image is too large for the core. |
Examples:
watershed_lines
¶
watershed_lines(
image: ArrayLike,
markers: ArrayLike,
connectivity: int,
*,
convert: bool = False,
) -> NDArray[np.bool_]
Watershed lines of a grey-level image, from markers.
Each marker region becomes the only minimum of its basin; the result is
True on the lines and False in the basins. The markers are
imposed at level 0, so two markers joined through points at 0 form one
region, with no line between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D |
required |
markers
|
array_like
|
|
required |
connectivity
|
int
|
As for |
required |
convert
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If the image is too large for the core. |
Examples:
>>> import numpy as np, digitopo
>>> image = np.array([[0, 50, 100, 200, 100, 50, 0],
... [0, 50, 100, 200, 100, 50, 0]], dtype=np.uint8)
>>> markers = np.zeros(image.shape, dtype=bool)
>>> markers[0, 0] = markers[0, 6] = True
>>> digitopo.watershed.watershed_lines(image, markers, 4).astype(int)
array([[0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0]])
watershed_labels
¶
watershed_labels(
image: ArrayLike, markers: ArrayLike, connectivity: int
) -> NDArray[np.integer[Any]]
Label the basins of the watershed from labelled markers.
The counterpart of skimage.segmentation.watershed(image, markers,
connectivity=..., watershed_line=True), with the lines of the
topological watershed: every point of a basin gets the label of the
markers it contains, and the lines get 0. Unlike scikit-image, the lines
are the crest lines of the topological watershed, which keeps the passes
between the basins at their level.
Every connected region of markers has its own basin. As in scikit-image, the basins of the same label are then joined: a line point whose labelled neighbours all have one label gets it, unless two labels would touch. The lines left separate different labels only.
Three differences with watershed_lines, which follows pink26:
- the markers are the only points at level 0: the other points at 0 are
raised to 1 first, so that two markers joined through points at 0 stay
two basins, separated by a line (in
watershed_linesthey form one region); - the points of a marker that touch a marker of another label (for
connectivity) are no longer markers: two touching markers would form one minimum, hence one basin. The line between the two basins then runs through their contact; imagemay be a float image in [0, 1], as in scikit-image: it is converted bydigitopo.interop.as_uint8, likebooland integer images from 0 to 255.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D grey-level image: |
required |
markers
|
array_like
|
Integer array of the shape of |
required |
connectivity
|
int
|
Connectivity of the basins and the markers: 4 or 8 in 2D, 6, 18 or 26
in 3D ( |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of the shape and dtype of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
DigitopoError
|
If |
Examples:
>>> import numpy as np, digitopo
>>> image = np.array([[0.0, 0.2, 0.4, 0.8, 0.4, 0.2, 0.0],
... [0.0, 0.2, 0.4, 0.8, 0.4, 0.2, 0.0]])
>>> markers = np.zeros(image.shape, dtype=np.int32)
>>> markers[0, 0], markers[0, 6] = 1, 2
>>> digitopo.watershed.watershed_labels(image, markers, 4)
array([[1, 1, 1, 0, 2, 2, 2],
[1, 1, 1, 0, 2, 2, 2]], dtype=int32)