phenotypic.detect.SecondaryOtsuDetector#

class phenotypic.detect.SecondaryOtsuDetector(*args, **kwargs)[source]

Bases: ThresholdDetector

Detect colonies by two-stage Otsu thresholding with per-object refinement.

Apply an initial global Otsu threshold (or reuse an existing objmask), then re-threshold each detected object independently using its own intensity distribution. This sharpens colony boundaries on plates where colonies vary in brightness, removing soft halos while preserving colony cores. For a full comparison see Detection Strategies Compared.

Returns:

Input image with objmask set to binary mask and objmap set to labeled connected components.

Return type:

Image

Best For:
  • Refining boundaries after an initial global threshold that leaves soft or blurry colony edges.

  • Heterogeneous plates where colonies differ in pigmentation or optical density across the plate surface.

  • Suppressing preprocessing halos that expand colony outlines beyond their true boundaries.

Consider Also:
  • OtsuDetector when a single global threshold already produces clean colony boundaries.

  • HysteresisDetector when colony intensity varies smoothly and dual-threshold expansion is more appropriate than per-object refinement.

  • RankOtsuDetector when spatially varying illumination is the primary cause of boundary inaccuracy.

References

[1] N. Otsu, “A threshold selection method from gray-level histograms,” IEEE Trans. Syst., Man, Cybern., vol. 9, no. 1, pp. 62–66, 1979.

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.