phenotypic.refine.LowCircularityRemover#

class phenotypic.refine.LowCircularityRemover(cutoff: float = 0.785)[source]#

Bases: ObjectRefiner

Remove objects with circularity below a specified cutoff.

Intuition:

Single bacterial/fungal colonies on agar often appear approximately round. Irregular, elongated, or fragmented shapes can indicate merged colonies, scratches, agar texture, or segmentation errors. Filtering by circularity keeps well-formed colonies and removes unlikely shapes.

Why this is useful for agar plates:

Circular colonies produce more reliable area and intensity measurements. Removing low-circularity detections reduces bias from streaks, debris, or incomplete segmentation near plate edges and grid borders.

Use cases:
  • Post-threshold cleanup to exclude elongated artifacts or merged colonies before counting or phenotyping.

  • Enforcing morphology consistency in high-throughput grid assays.

Caveats:
  • Some colonies are intrinsically irregular (wrinkled, spreading, filamentous). A high cutoff may incorrectly remove these phenotypes.

  • Perimeter estimates on low-resolution masks can be noisy, slightly biasing the circularity calculation.

Parameters:

cutoff (float)

cutoff#

Minimum Polsby–Popper circularity required to keep an object, in [0, 1]. Higher values retain only near-circular shapes (sharper shape constraints) and can improve edge sharpness in the kept set but may reduce recall for irregular colonies.

Type:

float

Examples

>>> from phenotypic.refine import LowCircularityRemover
>>> op = LowCircularityRemover(cutoff=0.8)
>>> image = op.apply(image, inplace=True)  

Methods

__init__

Initialize the remover.

apply

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

dispose_widgets

Drop references to the UI widgets.

sync_widgets_from_state

Push internal state into widgets.

widget

Return (and optionally display) the root widget.

__init__(cutoff: float = 0.785)[source]#

Initialize the remover.

Parameters:

cutoff (float) – Minimum allowed circularity in [0, 1]. Increasing the cutoff favors compact, round objects (often cleaner masks), whereas lowering it retains irregular colonies but may keep more debris or merged objects.

Raises:

ValueError – If cutoff is outside [0, 1].

__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

dispose_widgets() None#

Drop references to the UI widgets.

Return type:

None

sync_widgets_from_state() None#

Push internal state into widgets.

Return type:

None

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.