phenotypic.detect.SinePeakDetector#
- class phenotypic.detect.SinePeakDetector(thresh_method: Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'] = 'otsu', subtract_background: bool = True, remove_noise: bool = True, footprint_width: int = 6, noise_radius: int = 1, smoothing_sigma: float = 2.0, min_peak_distance: int | None = None, peak_prominence: float | None = None, edge_refinement: bool = True, correlation_threshold: float = 0.3, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = True)[source]
Bases:
GridInferenceMixin,ObjectDetectorDetect colonies on gridded plates using sinusoidal cross-correlation peak finding.
Generate a sinusoidal template matching the expected colony periodicity, compute FFT-based rank (Spearman) cross-correlation against row and column projection signals, and select peaks from the correlation output to locate grid positions. Rank-based correlation is insensitive to outlier colonies and monotonic intensity transformations, making this more robust than direct peak finding on plates with heterogeneous growth. For a full comparison see Detection Strategies Compared.
- Parameters:
thresh_method (Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li']) – Thresholding method for binary mask creation. Accepted values:
'otsu','mean','local','triangle','minimum','isodata','li'. Default:'otsu'.subtract_background (bool) – Apply white tophat transform to remove uneven illumination before thresholding. Default: True.
remove_noise (bool) – Apply morphological opening to remove small noise artifacts from the binary mask. Default: True.
footprint_width (int) – Width in pixels for the background subtraction kernel. When a GridImage is provided, an adaptive kernel sized to 1.5x colony spacing is used instead. Default: 6.
noise_radius (int) – Radius of the diamond structuring element for morphological noise removal. Default: 1.
smoothing_sigma (float) – Standard deviation for Gaussian smoothing of row/column intensity profiles before cross-correlation. Higher values smooth noise but may merge adjacent peaks. Set to 0 to disable. Default: 2.0.
min_peak_distance (int | None) – Minimum pixel distance between detected peaks. If
None, automatically estimated from grid dimensions. Default: None.peak_prominence (float | None) – Minimum prominence for peak detection. If
None, auto-calculated as 0.1 * signal range. Higher values are more selective. Default: None.edge_refinement (bool) – Refine grid edges using weighted local intensity profiles for improved accuracy. Default: True.
correlation_threshold (float) – Minimum normalised cross-correlation for a peak to be valid. Lower values accept weaker matches; higher values are more selective. Typical range: 0.1–0.5. Default: 0.3.
selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing one object per grid cell.
"dominant"keeps the largest object by pixel count."centered"keeps the object closest to the cell centre."regularized"fits a global regular-grid model from median centroids, then re-selects per cell. Default:"dominant".split_merged (bool) – Pre-split merged colonies spanning multiple grid cells using EDT watershed before grid assignment. Default: True.
- Returns:
Input image with
objmaskset to binary mask andobjmapset to labeled connected components.- Return type:
Image
- Raises:
ValueError – If
thresh_methodis not one of the accepted values.
- Best For:
Gridded plates (96-well, 384-well, pinned arrays) where colonies are arranged in a regular periodic pattern.
Plates with heterogeneous colony sizes or uneven growth where rank-based correlation outperforms intensity-based peak finding.
High-throughput batch processing of arrayed plates without manual grid specification.
- Consider Also:
RoundPeaksDetectorfor a simpler grid detector when colony intensities are uniform and direct peak finding suffices.OtsuDetectorwhen colonies are not gridded and a global threshold is appropriate.RankOtsuDetectorwhen spatial illumination variation is the primary challenge rather than grid localisation.
References
[1] O. Wagih and L. Parts, “gitter: a robust and accurate method for quantification of colony sizes from plate images,” G3 (Bethesda), vol. 4, no. 3, pp. 547–552, 2014.
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
Initialize the SinePeakDetector with specified parameters.
Detect colonies using sinusoidal cross-correlation grid estimation.
Return (and optionally display) the root widget.
- __init__(thresh_method: Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'] = 'otsu', subtract_background: bool = True, remove_noise: bool = True, footprint_width: int = 6, noise_radius: int = 1, smoothing_sigma: float = 2.0, min_peak_distance: int | None = None, peak_prominence: float | None = None, edge_refinement: bool = True, correlation_threshold: float = 0.3, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = True)[source]
Initialize the SinePeakDetector with specified parameters.
- Parameters:
thresh_method (Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li']) – Method for thresholding the image. Options are: ‘otsu’ (default), ‘mean’, ‘local’, ‘triangle’, ‘minimum’, ‘isodata’, ‘li’.
subtract_background (bool) – If True, apply white tophat transform to remove background variations before thresholding.
remove_noise (bool) – If True, apply morphological opening to remove small noise artifacts from the binary mask.
footprint_width (int) – Width in pixels for the background subtraction kernel. When a GridImage is provided, an adaptive kernel sized to 1.5x colony spacing is used instead, making this a fallback.
noise_radius (int) – Radius for the diamond structuring element used in morphological noise removal. Default 1 (3x3 diamond, matching gitter). Increase for larger noise artifacts.
smoothing_sigma (float) – Standard deviation for Gaussian smoothing of intensity profiles before cross-correlation. Set to 0 to disable smoothing.
min_peak_distance (int | None) – Minimum allowed distance between detected peaks. If None, automatically estimated from grid dimensions.
peak_prominence (float | None) – Minimum prominence required for peak detection. If None, automatically calculated as 0.1 * signal range.
edge_refinement (bool) – If True, refine grid edges using weighted intensity profiles for improved accuracy.
correlation_threshold (float) – Minimum normalized cross-correlation value for a peak to be considered valid. Default 0.3. Values below this threshold are zeroed before peak detection.
selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing one object per grid cell. ‘dominant’ (default) keeps the largest, ‘centered’ keeps the most centred, ‘regularized’ uses a global fit.
split_merged (bool) – If True (default), pre-split merged colonies that span multiple grid cells using EDT watershed before assignment.
- __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.