phenotypic.detect.RankOtsuDetector#
- class phenotypic.detect.RankOtsuDetector(shape: Literal['square', 'diamond', 'disk'] = 'square', width: int | None = None, ignore_zeros: bool = False)[source]
Bases:
ObjectDetector,FootprintMixinDetect colonies by adaptive local Otsu thresholding within a sliding footprint.
Compute an Otsu threshold independently for every pixel using a local spatial neighbourhood, producing a per-pixel adaptive threshold map. This compensates for vignetting, lighting gradients, and spatially varying agar colour that cause a single global threshold to over- or under-segment parts of the plate. For a full comparison see Detection Strategies Compared.
- Parameters:
shape (Literal['square', 'diamond', 'disk']) – Footprint shape for the local neighbourhood. Accepted values:
'square','diamond','disk'. Disk and diamond are rotationally symmetric; square is faster. Default:'square'.width (int | None) – Footprint width (or radius for disk/diamond) in pixels. If
None, auto-scales tomin(height, width) // 8. Larger values smooth the threshold spatially (less local adaptation); smaller values track finer illumination changes but may over-segment. Default: None.ignore_zeros (bool) – Exclude zero-intensity pixels from the local threshold computation. Enable for plates with black borders or masked regions. Default: False.
- Returns:
Input image with
objmaskset to binary mask andobjmapset to labeled connected components.- Return type:
Image
- Raises:
ValueError – If
shapeis not one of the accepted values orwidthis not positive.
- Best For:
Plates with vignetting, hot-spots, or centre-to-edge illumination gradients.
Large-format plates (384-well or larger) where lighting uniformity is difficult to achieve.
Images with spatially varying agar colour or reflectance.
- Consider Also:
OtsuDetectorwhen illumination is uniform and a fast global threshold suffices.HysteresisDetectorwhen colony brightness varies but spatial illumination is reasonably even.ChanVeseDetectorwhen colonies have diffuse edges and region-based segmentation is more appropriate.
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.