phenotypic.detect.HysteresisDetector#
- class phenotypic.detect.HysteresisDetector(low: str | float = 'mean', high: str | float = 'otsu', ignore_zeros: bool = False, ignore_borders: bool = True)[source]
Bases:
ThresholdDetectorDetect colonies by dual-threshold hysteresis, bridging bright cores to faint edges.
Seed strong colony regions that exceed the high threshold and expand each seed via pixel connectivity to include neighbouring pixels above the low threshold. This two-pass approach captures colonies whose intensity varies from bright centres to faint margins – a common pattern across growth stages and under uneven illumination. For a full comparison see Detection Strategies Compared.
- Parameters:
low (Union[str, float]) – Lower threshold controlling expansion sensitivity. Accepts a method name (
'otsu','triangle','li','yen','isodata','mean','minimum') for automatic computation, or a float for a manual value (0–255 for 8-bit, 0–65535 for 16-bit). Default'mean'. Lower values include more faint colony pixels but increase false positives. Typical tuning: start with'mean'and switch to a numeric value if automatic methods are too aggressive or too conservative.high (Union[str, float]) – Upper threshold seeding strong colony regions. Same format as low. Default
'otsu'. Must be >= low after computation. Higher values restrict seeds to the brightest colony pixels, producing fewer but higher-confidence detections.ignore_zeros (bool) – If True (default), exclude zero-intensity pixels from automatic threshold computation. Enable for plates with black borders or masked regions.
ignore_borders (bool) – If True (default), remove colonies touching image edges via
clear_border(). Recommended for grid-based colony counting.
- Returns:
Input image with
objmaskset to a binary colony mask where True pixels are colony foreground (including faint pixels connected to strong seed regions).objmapis not modified.- Return type:
Image
- Raises:
ValueError – If the computed high threshold is less than the computed low threshold, or if an unrecognised threshold method name is provided.
- Best For:
Plates where colony brightness varies (e.g., young versus mature growth, or centre-to-edge intensity gradients within a colony).
Noisy agar backgrounds where isolated noise pixels sit above a single threshold but lack connectivity to true colony regions.
Moderate vignetting or lighting gradients that cause a single global threshold to over- or under-segment parts of the plate.
Mixed-species plates where different organisms produce colonies of different intensities on the same agar.
- Consider Also:
OtsuDetectorwhen colony and background peaks are balanced and a single threshold suffices.WatershedDetectorwhen touching colonies must be split into individually labelled regions.CannyDetectorwhen colonies are best delineated by edge contrast rather than intensity.
See also
- Tutorial 2: Detecting Colonies
Step-by-step tutorial for basic colony detection.
- How To: Choose a Detection Algorithm
Guide for selecting the right detector for your plate images.
- Detection Strategies Compared
In-depth comparison of all detection strategies.
Methods
__init__Detect colonies using sinusoidal cross-correlation grid estimation.
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)
Detect colonies using sinusoidal cross-correlation grid estimation.
This method performs the core detection workflow: 1. Extract grid dimensions (if GridImage) 2. Threshold the detection matrix with adaptive kernel sizing 3. Remove noise if requested 4. Label connected components 5. Determine or estimate grid edges (via sinusoidal cross-correlation) 6. Assign dominant colonies to grid cells 7. Create final object map
- Parameters:
image – Image object to process. Can be a regular Image or GridImage.
- Returns:
The processed image with updated objmask and objmap.
- Return type:
Image
- widget(image: Image | None = None, show: bool = False) Widget
Return (and optionally display) the root widget.
- Parameters:
image (Image | None) – Optional image to visualize. If provided, visualization controls will be added to the widget.
show (bool) – Whether to display the widget immediately. Defaults to False.
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.