phenotypic.refine.SineAlignmentRefiner#

class phenotypic.refine.SineAlignmentRefiner(smoothing_sigma: float = 2.0, min_peak_distance: int | None = None, peak_prominence: float | None = None, edge_refinement: bool = True, correlation_threshold: float = 0.3, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = False)[source]

Bases: GridInferenceMixin, ObjectRefiner

Retain only grid-aligned colonies using sinusoidal cross-correlation for grid estimation.

Estimates grid edges by computing FFT-based normalized cross-correlation against a sinusoidal template of expected colony periodicity, then keeps one dominant object per cell. Rank-based (Spearman) correlation provides robustness to outlier colony intensities and monotonic intensity transformations compared to simple peak-finding.

Parameters:
  • smoothing_sigma (float) – Gaussian smoothing sigma for intensity profiles. 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 grid peaks. None auto-estimates. Default: None.

  • peak_prominence (float | None) – Minimum prominence for peak detection. None auto-calculates. Default: None.

  • edge_refinement (bool) – Refine grid edges using local intensity minima. Default: True.

  • correlation_threshold (float) – Minimum NCC value for a valid peak. Typical range: 0.1–0.6. Lower values accept weaker matches; higher values are more selective. Default: 0.3.

  • selection_mode (Literal['dominant', 'centered', 'regularized']) – Strategy for choosing one object per cell. "dominant" keeps the largest, "centered" keeps the most centered, "regularized" fits a global model. Default: "dominant".

  • split_merged (bool)

Returns:

Input image with objmap filtered to grid-aligned objects and objmask updated to match.

Return type:

Image

Raises:

ValueError – If grid inference fails or image lacks detection results.

Best For:
  • Gridded plates (96-well, 384-well, pinned cultures) where colony intensities are heterogeneous or unevenly grown.

  • Post-detection cleanup when simple peak-finding grid estimation is unreliable.

  • Plates with variable colony sizes or uneven growth where rank-based correlation outperforms direct intensity matching.

Consider Also:

References

[1] O. Wagih and L. Parts, “gitter: a robust and accurate method for quantification of colony sizes from plate images,” G3 (Bethesda), vol. 4, no. 3, pp. 547–552, 2014.

See also

How To: Refine Noisy Detection Boundaries for grid-based cleanup workflows. Refinement Strategies for a comparison of grid refinement approaches.

Methods

__init__

Initialize SineAlignmentRefiner with grid inference and correlation parameters.

apply

Applies the operation to an image, either in-place or on a copy.

widget

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, correlation_threshold: float = 0.3, selection_mode: Literal['dominant', 'centered', 'regularized'] = 'dominant', split_merged: bool = False)[source]

Initialize SineAlignmentRefiner with grid inference and correlation 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.

  • correlation_threshold (float) – Minimum NCC value for valid peaks.

  • 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.