phenotypic.detect.WatershedDetector#
- class phenotypic.detect.WatershedDetector(footprint: Literal['auto'] | numpy.ndarray | int | None = None, min_size: int = 50, compactness: float = 0.001, connectivity: int = 1, relabel: bool = True, ignore_zeros: bool = True)[source]#
Bases:
ThresholdDetectorClass for detecting objects in an image using the Watershed algorithm.
The WatershedDetector class processes images to detect and segment objects by applying the watershed algorithm. This class extends the capabilities of ThresholdDetector and includes customization for parameters such as footprint size, minimum object size, compactness, and connectivity. This is useful for image segmentation tasks, where proximity-based object identification is needed.
Note
Its recommended to use GaussianBlur beforehand
- Parameters:
- footprint#
Structure element to define the neighborhood for dilation and erosion operations. Can be specified directly as ‘auto’, an ndarray, an integer for diamond size, or None for implementation-based determination.
- Type:
Literal[‘auto’] | np.ndarray | int | None
- min_size#
Minimum size of objects to retain during segmentation. Objects smaller than this other_image are removed.
- Type:
- compactness#
Compactness parameter controlling segment shapes. Higher values enforce more regularly shaped objects.
- Type:
- connectivity#
The connectivity level used for determining connected components. Represents the number of dimensions neighbors need to share (1 for fully connected, higher values for less connectivity).
- Type:
- relabel#
Whether to relabel segmented objects during processing to ensure consistent labeling.
- Type:
- ignore_zeros#
Whether to exclude zero-valued pixels from threshold calculation. When True, Otsu threshold is calculated using only non-zero pixels, and zero pixels are automatically treated as background. When False, all pixels (including zeros) are used for threshold calculation. Default is True, which is useful for microscopy images where zero pixels represent true background or imaging artifacts.
- Type:
Methods
__init__Binarizes the given image gray using the Yen threshold method.
Drop references to the UI widgets.
Push internal state into widgets.
Return (and optionally display) the root widget.
- __del__()#
Automatically stop tracemalloc when the object is deleted.
- __getstate__()#
Prepare the object for pickling by disposing of any widgets.
This ensures that UI components (which may contain unpickleable objects like input functions or thread locks) are cleaned up before serialization.
Note
This method modifies the object state by calling dispose_widgets(). Any active widgets will be detached from the object.
- apply(image, inplace=False)#
Binarizes the given image gray using the Yen threshold method.
This function modifies the arr image by applying a binary mask to its enhanced gray (enh_gray). The binarization threshold is automatically determined using Yen’s method. The resulting binary mask is stored in the image’s objmask attribute.
- widget(image: Image | None = None, show: bool = False) Widget#
Return (and optionally display) the root widget.
- Parameters:
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.