phenotypic.refine.SmallObjectRemover#
- class phenotypic.refine.SmallObjectRemover(min_size=64)[source]#
Bases:
ObjectRefinerRemove small, likely spurious objects from a labeled object map.
- Intuition:
After thresholding/segmentation of agar-plate images, tiny specks from dust, condensation, camera noise, or over-segmentation can appear as separate labeled objects. Removing these below a minimum size reduces false positives and stabilizes downstream phenotyping.
- Use cases (agar plates):
Clean up salt-and-pepper detections before measuring colony size or shape.
Suppress fragmented debris around large colonies that may bias counts or area statistics.
Post-processing step after aggressive enhancement/thresholding.
- Tuning and effects:
min_size: Sets the minimum object area (in pixels). Increasing this value removes more small fragments, typically improving mask quality and background suppression, but may also delete legitimate micro- colonies when colonies are extremely small or underexposed.
- Caveats:
Setting
min_sizetoo high can remove small but real colonies or early-time-point growth, reducing recall.The optimal threshold depends on resolution; what is “small” at high-resolution imaging may be substantial at low resolution.
- (No public attributes)
Examples
Remove small spurious objects below a minimum size
>>> from phenotypic.refine import SmallObjectRemover >>> op = SmallObjectRemover(min_size=100) >>> image = op.apply(image, inplace=True)
Methods
Initialize the remover.
Applies the operation to an image, either in-place or on a copy.
Drop references to the UI widgets.
Push internal state into widgets.
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.
- widget(image: Image | None = None, show: bool = False) Widget#
Return (and optionally display) the root widget.
- Parameters:
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.