Watershed Segmentation

pylena.morpho.watershed(img: ndarray, connectivity: int, waterline: bool = True, markers: ndarray | None = None) Tuple[ndarray, int]

Performs a Watershed segmentation using the Meyer’s Watershed algorithm [6] on an image img using the neighborhood relationship connectivity.

Parameters:
  • img (2-D array (dtype=uint8)) – The input image

  • connectivity (int) – The connectivity used by the watershed. Should be 4 (for 4-connectivity) or 8 (for 8-connectivity)

  • waterline (bool) – Boolean to either display the watershed lines or

  • markers (Optional[np.ndarray]) – Optional image (dtype=int16) representing the input markers. In this case, the watershed is computed from markers and not from local minima and it returns the watershed segmentation from this markers with watershed lines (waterline argument is ignored in this case)

Returns:

The resulting segmentation

Return type:

Tuple[np.ndarray, int]

Raises:

ValueError – If the connectivity is invalid or the input image is not & 2-D array with values encoded as uint8 value