phenotypic.detect.ChanVeseDetector#
- class phenotypic.detect.ChanVeseDetector(mu: float = 0.25, lambda1: float = 1.0, lambda2: float = 1.0, max_num_iter: int = 500, tol: float = 0.001, dt: float = 0.5, init_level_set: str = 'checkerboard', min_size: int = 50, connectivity: int = 2)[source]
Bases:
ObjectDetectorDetect colonies by region-based level-set segmentation using the Chan-Vese energy functional.
Partition the image into foreground and background by minimising an energy functional based on intensity homogeneity within each region. Because segmentation is driven by region statistics rather than edge gradients, colonies with diffuse boundaries, uneven texture, or gradual transitions into the agar background are captured cleanly. For algorithm details see Detection Strategies Compared.
- Parameters:
mu (float) – Edge-length penalty weight. Higher values produce smoother, rounder colony outlines; lower values preserve fine boundary detail. Typical range: 0.05–1.0. Default: 0.25.
lambda1 (float) – Weight for intensity deviation inside detected regions. Increase to enforce uniform colony brightness. Default: 1.0.
lambda2 (float) – Weight for intensity deviation outside detected regions. Increase when the agar background is homogeneous. Default: 1.0.
max_num_iter (int) – Maximum level-set iterations. Increase for complex images where convergence is slow; decrease for faster (but potentially incomplete) segmentation. Default: 500.
tol (float) – Convergence tolerance (L2 norm of level-set change). Smaller values require tighter convergence but more iterations. Default: 1e-3.
dt (float) – Step-size multiplier for level-set evolution. Larger values evolve faster but risk instability. Default: 0.5.
init_level_set (str) – Initialisation method for the level set. Accepted values:
"checkerboard","disk","small disk". Checkerboard is robust for most plate images. Default:"checkerboard".min_size (int) – Minimum colony area in pixels. Connected components smaller than this are removed as noise. Default: 50.
connectivity (int) – Pixel connectivity for labelling connected components.
1for 4-connectivity,2for 8-connectivity. Default: 2.
- Returns:
Input image with
objmaskset to binary mask andobjmapset to labeled connected components.- Return type:
Image
- Raises:
ValueError – If
init_level_setis not a recognised initialisation method.
- Best For:
Mucoid or fuzzy colonies whose edges lack sharp intensity gradients.
Plates with uneven colony pigmentation or heterogeneous surface texture that fragments threshold-based masks.
Low-contrast imaging where colony and agar intensities are similar.
Morphology studies where smooth, accurate colony outlines are required.
- Consider Also:
OtsuDetectorwhen colonies and background form two clear histogram peaks and a fast global threshold suffices.HysteresisDetectorwhen colony brightness varies but edges are still reasonably sharp.CannyDetectorwhen colonies are best delineated by edge contrast rather than region homogeneity.
References
[1] T. F. Chan and L. A. Vese, “Active contours without edges,” IEEE Trans. Image Process., vol. 10, no. 2, pp. 266–277, 2001.
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.