phenotypic.refine.GridAlignmentRefiner#
- class phenotypic.refine.GridAlignmentRefiner(smoothing_sigma: float = 2.0, min_peak_distance: int | None = None, peak_prominence: float | None = None, edge_refinement: bool = True, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = False)[source]
Bases:
GridInferenceMixin,ObjectRefinerRetain only grid-aligned colonies by keeping the dominant object per cell.
Infers or reads grid geometry, partitions the image into cells, and keeps one object per cell according to the chosen selection strategy. Off-grid artifacts, dust, and spurious detections are removed, enforcing regular grid structure on colony detection results.
- Parameters:
smoothing_sigma (float) – Gaussian smoothing sigma for row/column intensity profiles during grid inference. Typical range: 0.5–5.0. Higher values smooth noise but may merge adjacent peaks. Default: 2.0.
min_peak_distance (int | None) – Minimum pixel distance between detected grid peaks.
Noneauto-estimates as half the expected colony spacing. Default: None.peak_prominence (float | None) – Minimum prominence for peak detection.
Noneauto-calculates as 10% of signal range. Default: None.edge_refinement (bool) – Refine grid edges using local intensity minima. Improves accuracy for unevenly lit plates. Default: True.
selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing one object per cell.
"dominant"keeps the largest by pixel count,"centered"keeps the most centered,"regularized"fits a global regular-grid model then re-selects. Default:"dominant".split_merged (bool)
- Returns:
Input image with
objmapfiltered to grid-aligned objects andobjmaskupdated to match.- Return type:
Image
- Raises:
ValueError – If grid inference fails or image lacks detection results.
- Best For:
High-throughput arrayed plates (96-well, 384-well, pinned cultures) where colonies should align with known well positions.
Post-detection cleanup when detections contain off-grid artifacts.
Explicit grid enforcement when used with GridImage and known grid coordinates.
- Consider Also:
SineAlignmentRefinerwhen colony intensities are heterogeneous and rank-based correlation improves grid estimation.GridSectionLargestfor a simpler largest-per-cell strategy on GridImage inputs.ReduceMultipleGridObjectsfor regression-based multi- detection reduction within grid cells.
See also
How To: Refine Noisy Detection Boundaries for grid-based cleanup workflows. Refinement Strategies for a comparison of grid refinement approaches.
Methods
Initialize GridAlignmentRefiner with grid inference parameters.
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(smoothing_sigma: float = 2.0, min_peak_distance: int | None = None, peak_prominence: float | None = None, edge_refinement: bool = True, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = False)[source]
Initialize GridAlignmentRefiner with grid inference parameters.
- Parameters:
smoothing_sigma (float) – Gaussian smoothing sigma for intensity profiles.
min_peak_distance (int | None) – Minimum distance between grid peaks.
peak_prominence (float | None) – Minimum prominence for peak detection.
edge_refinement (bool) – Enable edge refinement via local intensity minima.
selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing the object per grid cell. ‘dominant’ (default) keeps the largest, ‘centered’ keeps the most centred, ‘regularized’ uses a global fit.
split_merged (bool) – If True, pre-split merged colonies that span multiple grid cells using EDT watershed before assignment. Default False for refiners (splitting is more useful during initial detection).
- apply(image, inplace=False)[source]
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
- __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.
- 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.