phenotypic.detect.FilamentousFungiDetector#
- class phenotypic.detect.FilamentousFungiDetector(inoculum_detector: ObjectDetector | ImagePipeline | None = None, max_colony_radius_px: float = 250.0, min_branch_width_px: int = 3, ignore_borders: bool = True, edge_noise_threshold: float = 6.0, reconnection_tolerance: float = 2.5, max_gap_length: int = 30, border_margin_px: int = 50, frag_reach_px: int = 10, gap_crossing_penalty: float = 4.0, *, gauss_sigma: float | None = None, tile_size: int | None = None, tile_overlap: int | None = None, pct_min_wavelength: float | None = None, mad_window: int | None = None, path_dilation_radius: int | None = None, snr_margin: int | None = None, coherence_window_radius: int | None = None)[source]
Bases:
GridObjectDetectorDetect and separate filamentous fungal colonies by two-stage detection with Euclidean Voronoi partition.
Segment filamentous fungi in two stages: (1) detect compact inoculation centres with an
inoculum_detector, (2) capture the full hyphal structure via phase-congruency-based branch detection and Dijkstra reconnection. Filtered centre centroids seed a Euclidean Voronoi partition that assigns every fungal pixel to its nearest colony, with connectivity-based correction ensuring uniform labelling within connected components. For a full comparison see Detection Strategies Compared.- Parameters:
inoculum_detector (Union[ObjectDetector, 'ImagePipeline', None]) – ObjectDetector or ImagePipeline that identifies compact fungal centres/nuclei. Should produce small, tight regions at inoculation points. Default uses an internal InoculumDetector + GridSectionLargest pipeline.
max_colony_radius_px (float) – Largest colony radius (in pixels) the detector should handle. Sizes scene-derived spatial parameters (
gauss_sigma,tile_size,tile_overlap) for this worst case. Default 250.min_branch_width_px (int) – Narrowest hyphal branch width (in pixels) to detect. Sizes signal-scale parameters (
pct_min_wavelength,mad_window,path_dilation_radius,snr_margin,coherence_window_radius). Default 3.ignore_borders (bool) – If True, drops objects touching the image border during hysteresis-threshold branch detection. Default True.
edge_noise_threshold (float) – Noise threshold scaling factor for phase congruency edge detection. Higher values are stricter (reject more pixels as noise; preserve fewer thin hyphae). Default 6.0.
reconnection_tolerance (float) – IQR multiplier for path quality threshold calibration. Higher values accept more reconnection paths (may bridge genuinely-missing hyphae but risks over-merging). Default 2.5.
max_gap_length (int) – Maximum acceptable length (pixels) of a suspicious cost stretch along a reconnection path. Paths with longer bad stretches are rejected. Default 30.
border_margin_px (int) – Border penalty buffer width in pixels. Prevents reconnection paths from routing along image borders. Default 50.
frag_reach_px (int) – Maximum 2D distance (pixels) from a fragment’s boundary to the nearest routable (low-cost) pixel. Fragments more isolated than this are dropped before Dijkstra routing, since no plausible path could connect them. Default 10.
gap_crossing_penalty (float) – Distance-gap penalty strength during Dijkstra routing. Higher values make paths route around low-PCT-energy gaps more aggressively. Default 4.0.
gauss_sigma (Optional[float]) – Override for SubtractGaussian sigma. If None (default), derived from
max_colony_radius_px.tile_size (Optional[int]) – Override for tile side length. If None (default), derived from
max_colony_radius_px.tile_overlap (Optional[int]) – Override for tile overlap. If None (default), derived from
max_colony_radius_px.pct_min_wavelength (Optional[float]) – Override for log-Gabor minimum wavelength. If None (default), derived from
min_branch_width_px.mad_window (Optional[int]) – Override for local MAD window size (must be odd). If None (default), derived from
min_branch_width_px.path_dilation_radius (Optional[int]) – Override for dilating reconnection paths. If None (default), derived from
min_branch_width_px.snr_margin (Optional[int]) – Override for SNR background ring radius beyond
path_dilation_radius. If None (default), derived frommin_branch_width_px.coherence_window_radius (Optional[int]) – Override for orientation coherence computation radius. If None (default), derived from
min_branch_width_px.
- Returns:
Input image with
objmaskset to a binary fungal mask andobjmapset to a labelled colony map where each fungal colony receives a unique integer label via Voronoi assignment.- Return type:
Image
- Raises:
TypeError – If inoculum_detector is not an ObjectDetector or ImagePipeline instance.
ValueError – If no centres are detected, no branch structure is detected, or no centres overlap with the branch structure after filtering.
- Best For:
Filamentous fungal colonies (e.g., Aspergillus, Neurospora, Trichoderma) with irregular, spreading hyphal morphologies.
Dense plates where neighbouring fungal colonies touch or overlap and must be individually labelled.
Time-course experiments tracking hyphal extension from compact inoculation sites.
Grid-based fungal culture plates (GridImage) where one colony per well must be quantified.
High-throughput fungal phenotyping screens requiring consistent separation quality across hundreds of plates.
- Consider Also:
WatershedDetectorwhen colonies are compact and roughly circular (yeast-like morphology).OtsuDetectorwhen fungi are well-separated and a simple binary mask suffices without individual labelling.CompositeDetectorwhen combining multiple detection strategies without the two-stage centre-plus-body approach.
References
[1] P. Kovesi, “Image features from phase congruency,” Videre: J. Comput. Vis. Res., vol. 1, no. 3, pp. 1–26, 1999.
See also
- Tutorial 10: Detecting Filamentous Fungi
Dedicated tutorial for filamentous fungi detection workflows.
- 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.
Attributes
- beta: float = 2.0
- gamma: float = 1.2
- gauss_n_iter: int = 2
- delta: float = 1.0
- pct_n_orient: int = 8
- __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.