phenotypic.refine.SmallObjectRemover#
- class phenotypic.refine.SmallObjectRemover(min_size=64)[source]
Bases:
ObjectRefinerRemove objects smaller than a minimum area from the detection mask.
Eliminates dust, condensation specks, and noise fragments that appear as tiny labeled objects after thresholding. Reduces false positives and stabilizes colony counts.
- Parameters:
min_size – Minimum object area in pixels to keep. Objects below this threshold are removed. Typical range: 20–200 depending on image resolution. Default: 64.
- Returns:
Input image with
objmaskandobjmapupdated to exclude small objects.- Return type:
Image
- Best For:
Cleaning up salt-and-pepper artifacts after detection.
Removing fragmented debris around large colonies.
Post-processing after aggressive enhancement or thresholding.
- Consider Also:
BorderObjectRemoverfor removing partial colonies at image edges (size-independent).LowCircularityRemoverfor removing non-circular artifacts regardless of size.
See also
How To: Refine Noisy Detection Boundaries for a walkthrough of refinement operations. Refinement Strategies for choosing the right refinement sequence.
Methods
Initialize the remover.
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(min_size=64)[source]
Initialize the remover.
- Parameters:
min_size (int) – Minimum object area (in pixels) to keep. Higher values remove more small artifacts and fragmented edges, generally improving mask cleanliness but risking loss of tiny colonies.
- __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.