phenotypic.detect.InoculumDetector#

class phenotypic.detect.InoculumDetector(min_diameter: float = 30.0, max_diameter: float = 100.0, thresh_method: Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'] = 'otsu', enable_gmm: bool = True, gmm_n_components: int = 2, gmm_separation_threshold: float = 0.9, validate_obj_count: bool = True)[source]

Bases: ObjectDetector

Detect inoculation sites on agar plates via Gaussian background subtraction and multi-scale blob enhancement.

Identify inoculation spots (from pin-deposition tools, liquid spotting, or serial dilutions) by composing Gaussian background subtraction, median filtering, multi-scale Laplacian-of-Gaussian blob enhancement, contrast stretching, morphological opening, round-peaks detection, and optional GMM-based core extraction. All processing occurs on a working copy so that image.detect_mat is never modified. For a full comparison see Detection Strategies Compared.

Parameters:
  • min_diameter (float) – Smallest expected inoculum diameter in pixels. Used to derive LoG minimum radius and GMM morphological parameters. Set based on the smallest visible spot in your images. Default 30.0. Typical range: 5–80.

  • max_diameter (float) – Largest expected inoculum diameter in pixels. Used to derive Gaussian background subtraction sigma and LoG maximum radius. Default 100.0. Typical range: 50–300. Must be greater than min_diameter.

  • thresh_method (Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li']) – Thresholding method for binary segmentation within the RoundPeaksDetector step. Options: 'otsu' (default), 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'. 'otsu' works well for most standardised setups; 'local' adapts to spatial illumination gradients.

  • enable_gmm (bool) – If True (default), apply Gaussian Mixture Model core extraction to refine detected regions to bright, compact cores. Disable for inocula that lack clear core-surround structure.

  • gmm_n_components (int) – GMM components per region (default 2). 2 separates core from surround; increase only for complex multi-layered spots.

  • gmm_separation_threshold (float) – Normalised Euclidean distance between GMM component means. Below this threshold a region is left unmodified (no clear core). Default 0.9. Typical range: 0.8–1.2. Increase to make refinement less aggressive.

  • validate_obj_count (bool) – If True (default) and the input is a GridImage, raise ValueError when the detected object count exceeds nrows * ncols. Catches over-segmentation early.

Returns:

Input image with objmask (binary inoculum mask) and objmap (labelled inoculum map) populated.

Return type:

Image

Raises:

ValueError – If detected object count exceeds grid capacity (when validate_obj_count is True and input is a GridImage), or if min_diameter >= max_diameter.

Best For:
  • Pin-tool inoculation on high-density plates (96-well, 384-well) where inocula are 30–80 pixels in diameter.

  • Spot-dilution assays producing 10–150 pixel inocula across serial dilution series.

  • Pre-growth phenotyping baselines (T=0 imaging) for establishing reference coordinates before growth measurements.

  • Liquid spotting assays where GMM core extraction refines boundaries for accurate area and circularity measurements.

Consider Also:
  • RoundPeaksDetector when colonies (not inocula) must be detected on a regular grid without multi-scale blob enhancement.

  • OtsuDetector when inocula are high-contrast and a simple global threshold is sufficient.

  • FilamentousFungiDetector when inoculation sites have developed into filamentous fungal growth.

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__

Initialise InoculumDetector with biology-driven parameters.

apply

Detect colonies using sinusoidal cross-correlation grid estimation.

widget

Return (and optionally display) the root widget.

__init__(min_diameter: float = 30.0, max_diameter: float = 100.0, thresh_method: Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li'] = 'otsu', enable_gmm: bool = True, gmm_n_components: int = 2, gmm_separation_threshold: float = 0.9, validate_obj_count: bool = True)[source]

Initialise InoculumDetector with biology-driven parameters.

Parameters:
  • min_diameter (float) – Smallest expected inoculum diameter (pixels). Default: 30.0.

  • max_diameter (float) – Largest expected inoculum diameter (pixels). Default: 100.0.

  • thresh_method (Literal['otsu', 'mean', 'local', 'triangle', 'minimum', 'isodata', 'li']) – Thresholding method. Default: 'otsu'.

  • enable_gmm (bool) – Apply GMM core extraction. Default: True.

  • gmm_n_components (int) – GMM components per region. Default: 2.

  • gmm_separation_threshold (float) – GMM mean separation threshold. Default: 0.9.

  • validate_obj_count (bool) – Validate object count for GridImage. Default: True.

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