phenotypic.refine.ResidualOutlierRemover#

class phenotypic.refine.ResidualOutlierRemover(axis: int | None = None, stddev_multiplier=1.5, max_coeff_variance: int = 1)[source]

Bases: GridObjectRefiner

Remove objects with large positional residuals in noisy grid rows or columns.

Fits linear-regression trends to colony centroids along each row and column, identifies rows/columns with high variability (coefficient of variance above threshold), and removes objects whose residual error exceeds an IQR-based cutoff within those noisy lines.

Parameters:
  • axis (Optional[int]) – Axis to analyze. None analyzes both rows and columns, 0 rows only, 1 columns only. Restricting the axis speeds processing and targets known problem directions. Default: None.

  • stddev_multiplier – IQR-based cutoff multiplier for outlier removal. Lower values prune more aggressively; higher values are conservative. Typical range: 1.0–3.0. Default: 1.5.

  • max_coeff_variance (int) – Maximum coefficient of variance (std/mean) allowed before a row/column is considered noisy and eligible for outlier pruning. Typical range: 1–5. Default: 1.

Returns:

Input image with objmap and objmask updated to exclude positional outliers from noisy grid rows/columns.

Return type:

Image

Best For:
  • Cleaning rows or columns with off-grid detections from condensation, glare, or debris before measuring growth.

  • Stabilizing grid registration when a subset of positions is noisy.

  • Plates where most grid lines are well-aligned but a few contain spurious artifacts.

Consider Also:

See also

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

Methods

__init__

Initialize the remover.

apply

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

widget

Return (and optionally display) the root widget.

__init__(axis: int | None = None, stddev_multiplier=1.5, max_coeff_variance: int = 1)[source]

Initialize the remover.

Parameters:
  • axis (Optional[int]) – Axis selection for analysis. None runs both directions; 0 rows; 1 columns. Limiting the axis reduces runtime and targets known problem directions.

  • stddev_multiplier (float) – Robust residual cutoff multiplier. Lower values remove more outliers (stronger cleanup) but risk dropping valid off-center colonies; higher values are conservative.

  • max_coeff_variance (int) – Threshold for row/column variability (std/mean) to trigger outlier analysis. Lower values clean more lines; higher values only address extremely noisy lines.

Raises:

ValueError – If parameters are not consistent with the operation (e.g., invalid types). Errors may arise during execution when measuring grid statistics.

__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)

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

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.