phenotypic.refine.GMMCoreExtractor#

class phenotypic.refine.GMMCoreExtractor(n_components: int = 2, separation_threshold: float = 0.8, min_core_area: int = 30, morph_open_radius: int = 1, morph_close_radius: int = 2)[source]

Bases: ObjectRefiner

Extract compact bright cores from labeled colonies using Gaussian mixture modeling.

Fits a two-component GMM to each colony’s intensity histogram, separating the bright inoculum core from the dimmer surrounding halo. Regions with insufficient intensity contrast are left unchanged. Morphological opening and closing refine the extracted core shape.

For algorithm details, see Refinement Strategies.

Parameters:
  • n_components (int) – Number of Gaussian components per region. Keep at 2 for canonical core-vs-surround splitting; higher values risk over-segmentation. Default: 2.

  • separation_threshold (float) – Normalized mean separation below which the original region is left unchanged. Typical range: 0.5–1.2. Higher values extract only high-confidence cores. Default: 0.8.

  • min_core_area (int) – Minimum core area in pixels. Regions or extracted cores smaller than this are kept as-is. Typical range: 10–500, scale with resolution. Default: 30.

  • morph_open_radius (int) – Radius of elliptical opening kernel. Removes thin protrusions; 0 disables. Typical range: 0–5. Default: 1.

  • morph_close_radius (int) – Radius of elliptical closing kernel. Fills small gaps within cores; 0 disables. Typical range: 0–5. Default: 2.

Returns:

Input image with objmap refined to bright-core masks.

Return type:

Image

Raises:

ValueError – If n_components is not a positive integer or if separation_threshold is negative.

Best For:
  • Rich media plates (YPD, LB) where colonies develop dense bright centers with obvious halos.

  • Pinned-array inoculation where sharp bright cores need to be isolated from thin outgrowth.

  • High-density plates (96-well, 384-well) where core extraction reduces inter-well spillover.

  • Pre-measurement cleanup to ensure features reflect the primary growth mass rather than diffusion halos.

Consider Also:
  • MaskEroder for uniform inward shrinking when cores are not intensity-distinct from halos.

  • WhiteTophat for removing small bright artifacts without full core extraction.

  • LowCircularityRemover for shape-based filtering when halos distort circularity measurements.

See also

How To: Refine Noisy Detection Boundaries for core extraction workflows. Refinement Strategies for a comparison of refinement approaches including GMM-based extraction.

Methods

__init__

Initialise the GMM core extractor.

apply

Applies the operation to an image, either in-place or on a copy.

widget

Return (and optionally display) the root widget.

__init__(n_components: int = 2, separation_threshold: float = 0.8, min_core_area: int = 30, morph_open_radius: int = 1, morph_close_radius: int = 2)[source]

Initialise the GMM core extractor.

Parameters:
  • n_components (int) – Number of Gaussian components to fit per labelled region (default 2 — core vs. surround).

  • separation_threshold (float) – Normalised mean separation below which the region is left unchanged (0.0–1.0+).

  • min_core_area (int) – Minimum core area in pixels. Regions or connected components below this size are kept as-is or discarded.

  • morph_open_radius (int) – Radius for morphological opening (0 disables).

  • morph_close_radius (int) – Radius for morphological closing (0 disables).

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

Applies the operation to an image, either in-place or on a copy.

Parameters:
  • image (Image) – The arr image to apply the operation on.

  • inplace (bool) – If True, modifies the image in place; otherwise, operates on a copy of the image.

Returns:

The modified image after applying the operation.

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.