phenotypic.refine.BorderObjectRemover#
- class phenotypic.refine.BorderObjectRemover(border_size: int | float | None = 1)[source]#
Bases:
ObjectRefinerRemove objects that touch the image border within a configurable margin.
- Intuition:
Colonies that intersect the plate boundary or image crop edge are often partial, poorly segmented, and bias size/shape measurements. This operation zeroes any labeled objects in
image.objmapwhose pixels fall within a user-defined border band, ensuring only fully contained colonies are analyzed.- Why this is useful for agar-plate imaging:
Plate crops or grid layouts frequently clip edge colonies. Removing border-touching objects stabilizes downstream phenotyping (area, circularity, intensity) and prevents partial colonies from contaminating statistics or training data.
- Use cases:
Single-plate captures where the plate rim truncates colonies.
Grid assays where wells or positions near the frame boundary are partially visible.
Automated crops that shift slightly between frames, cutting off colonies at the margins.
- Caveats:
A large border may remove valid edge colonies (lower recall). Too small a border may retain partial objects.
With very tight crops (little background), even modest margins can eliminate many colonies.
Examples
Remove objects that touch the image border within a margin
>>> from phenotypic.refine import BorderObjectRemover >>> op = BorderObjectRemover(border_size=15) >>> image = op.apply(image, inplace=True) >>> # All colonies intersecting a 15-pixel frame margin are removed
- Raises:
TypeError – If an invalid
border_sizetype is provided (raised during operation when parameters are validated).- Parameters:
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__(border_size: int | float | None = 1)[source]#
Initialize the remover.
- Parameters:
border_size (int | float | None) –
Width of the exclusion border around the image. -
None: Use a default margin equal to 1% of the smallerimage dimension.
floatin (0, 1): Interpret as a fraction of the minimum image dimension, producing a resolution-adaptive margin.intorfloat≥ 1: Interpret as an absolute number of pixels.
Notes
Larger margins remove more edge-touching colonies and are useful when crops are loose or the plate rim intrudes. Smaller margins preserve edge colonies but risk including partial objects.
- __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.