phenotypic.detect.CompositeDetector#

class phenotypic.detect.CompositeDetector(detectors: List[ObjectDetector | 'ImagePipeline'] = None, mode: Literal['union', 'intersection', 'overlap'] = 'overlap', min_overlap_ratio: float = 0.0)[source]

Bases: ObjectDetector

Detect colonies by combining multiple detectors via union, intersection, or overlap filtering.

Apply two or more detection algorithms (or preprocessing pipelines ending in a detector) to the same plate image and merge their binary masks. Ensemble combination improves sensitivity (union), specificity (intersection), or both (overlap filtering). This is especially useful for challenging plates where no single algorithm captures all colonies reliably. For a full comparison see Detection Strategies Compared.

Parameters:
  • detectors (List[Union[ObjectDetector, 'ImagePipeline']]) – List of ObjectDetector or ImagePipeline instances to combine. Pipelines allow preprocessing steps before detection. Defaults to [OtsuDetector(), RoundPeaksDetector()] when not specified.

  • mode (Literal['union', 'intersection', 'overlap']) – Combination strategy. 'union' marks a pixel as colony if any detector flags it (logical OR, maximises sensitivity). 'intersection' requires all detectors to agree (logical AND, maximises specificity). 'overlap' retains whole objects that have mutual spatial overlap across masks (balances sensitivity and specificity). Default 'overlap'.

  • min_overlap_ratio (float) – For 'overlap' mode, minimum fraction of object pixels that must overlap with all other masks. Range: 0.0–1.0. Default 0.0. Higher values produce more conservative filtering. Typical range: 0.0–0.5.

Returns:

Input image with objmask set to the combined binary colony mask and objmap derived from the merged mask.

Return type:

Image

Raises:

ValueError – If detectors list is empty or mode is not one of 'union', 'intersection', or 'overlap'.

Best For:
  • Plates where different colony sub-populations respond to different detection algorithms (e.g., bright colonies via Otsu, faint colonies via triangle thresholding).

  • Consensus-based quality control that accepts only colonies confirmed by all methods.

  • Ensemble strategies that maximise recall by unioning masks from complementary algorithms.

  • Benchmarking workflows that compare detector agreement.

Consider Also:

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__

apply

Detect colonies using sinusoidal cross-correlation grid estimation.

widget

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.