phenotypic.detect.RoundPeaksDetector#

class phenotypic.detect.RoundPeaksDetector(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, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = True)[source]

Bases: GridInferenceMixin, ObjectDetector

Detect round colonies on gridded plates by row/column peak analysis (gitter algorithm).

Threshold the plate image, project row and column intensity sums to detect periodic peaks, infer grid edges from peak positions, and assign one colony per grid cell. This implements the gitter algorithm optimised for pinned microbial culture plates with circular colonies arranged in regular arrays (96, 384, 1536 formats). 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. Options: 'otsu' (default), 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'. 'otsu' works well for most standardised imaging setups; 'local' adapts to spatial illumination gradients.

  • subtract_background (bool) – If True (default), apply white tophat transform to remove uneven illumination before thresholding. Disable on plates with uniform lighting to save compute time.

  • remove_noise (bool) – If True (default), apply morphological opening to remove small noise artefacts from the binary mask.

  • footprint_width (int) – Width in pixels for the background subtraction kernel (default 6). When a GridImage is provided, an adaptive kernel sized to 1.5x colony spacing is used instead, making this a fallback for plain Image inputs. Typical range: 4–20.

  • noise_radius (int) – Radius of the diamond structuring element for morphological noise removal (default 1, yielding a 3x3 diamond). Increase for larger noise artefacts. Typical range: 1–3.

  • smoothing_sigma (float) – Gaussian sigma for smoothing row/column intensity profiles before peak detection (default 2.0). Higher values suppress noise but may merge adjacent colony peaks. Set to 0 to disable smoothing. Typical range: 0–5.0.

  • min_peak_distance (int | None) – Minimum pixel distance between detected peaks. If None (default), automatically estimated from grid dimensions.

  • peak_prominence (float | None) – Minimum prominence threshold for peak detection. If None (default), auto-calculated as 0.1 * signal range. Higher values are more selective. Typical range: 0.05–0.3 of signal range.

  • edge_refinement (bool) – If True (default), refine grid edges using weighted local intensity profiles for improved accuracy.

  • selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing one object per grid cell. "dominant" (default) keeps the largest object by pixel count. "centered" keeps the object whose centroid is closest to the cell centre. "regularized" fits a global regular-grid model from median row/column centroids, then re-selects per cell – best for pinned arrays.

  • split_merged (bool) – If True (default), pre-split merged colonies that span multiple grid cells using EDT watershed before grid assignment. Set to False when colonies are well-separated and splitting is unnecessary.

Returns:

Input image with objmask set to a binary colony mask and objmap set to a labelled colony map with one label per grid cell.

Return type:

Image

Raises:

ValueError – If an invalid thresholding method is specified.

Best For:
  • Pinned yeast or bacterial plates with colonies arranged in a regular rectangular grid.

  • Plates where colony shape is approximately circular and colonies are well-separated or only mildly touching.

  • High-throughput screens where automatic grid inference eliminates the need for manual grid specification.

  • Workflows that require one-colony-per-cell assignment for downstream quantification.

Consider Also:
  • WatershedDetector when colonies are densely packed and touching but not arranged on a regular grid.

  • FilamentousFungiDetector when colonies exhibit spreading, filamentous growth that violates the round-colony assumption.

  • OtsuDetector when a simple binary mask is sufficient and per-cell assignment is not needed.

  • ManualGridDetector when colony positions are known a priori from robotic spotting coordinates.

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

__init__

Initialize the RoundPeaksDetector with specified parameters.

apply

Detect colonies using sinusoidal cross-correlation grid estimation.

widget

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, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = True)[source]

Initialize the RoundPeaksDetector 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 peak detection. 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.

  • 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.