phenotypic.detect.ManualDetector#
- class phenotypic.detect.ManualDetector(threshold: float = 0.5, ignore_zeros: bool = False, ignore_borders: bool = True)[source]
Bases:
ThresholdDetectorDetect colonies by applying a user-specified intensity threshold.
Apply a fixed intensity cutoff to the plate detection matrix, producing a binary colony mask without any automatic threshold computation. This gives explicit control over detection sensitivity and is the preferred approach when empirical testing has identified an optimal threshold for a specific imaging setup. For a full comparison see Detection Strategies Compared.
- Parameters:
threshold (float) – Intensity cutoff for binary segmentation. Pixels with intensity >= threshold become colony (True), others become background (False). For 8-bit images the valid range is 0–255; for 16-bit images 0–65535; for float images 0.0–1.0. Higher values are more conservative (fewer colonies detected); lower values are more sensitive (more colonies, more noise). Default 0.5. Start by inspecting the image histogram to find the valley between background and colony peaks.
ignore_zeros (bool) – If True (default), exclude zero-intensity pixels from processing. Enable for plates with black borders or masked regions.
ignore_borders (bool) – If True (default), remove colonies touching image edges via
clear_border(). Recommended for grid-based colony counting.
- Returns:
Input image with
objmaskset to a binary colony mask (True = colony, False = background).objmapis not modified.- Return type:
Image
- Raises:
ValueError – If threshold is negative.
- Best For:
Standardised imaging setups where the optimal threshold has been determined empirically and remains stable across plates.
Overriding automatic methods (Otsu, triangle, etc.) that consistently over- or under-segment on a particular plate type.
High-contrast plates where colonies are uniformly bright or dark relative to background and a single cutoff cleanly separates foreground from background.
Reproducibility-critical workflows where a fixed numeric threshold eliminates variability introduced by automatic selection.
- Consider Also:
OtsuDetectorwhen an automatic, parameter-free threshold is preferred and the histogram is bimodal.HysteresisDetectorwhen colony intensity varies across the plate and a single threshold cannot capture all colonies.TriangleDetectorwhen colonies are sparse and the histogram is skewed toward background.
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__Detect colonies using sinusoidal cross-correlation grid estimation.
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.