phenotypic.refine.MaskFill#
- class phenotypic.refine.MaskFill(structure: numpy.ndarray | None = None, origin: int = 0)[source]
Bases:
ObjectRefinerFill holes inside colony masks to produce solid, contiguous regions.
Uses binary flood fill to close voids left by illumination gradients, pigment heterogeneity, or glare within colonies. Produces masks that better match the true colony footprint for area and shape measurements.
- Parameters:
structure (Optional[np.ndarray]) – Binary structuring element defining the fill neighborhood.
Noneuses the default cross-shaped element. Default:None.origin (int) – Center offset for the structuring element. Default: 0.
- Returns:
Input image with
objmaskandobjmapupdated with filled holes.- Return type:
Image
- Best For:
Donut-like masks from global thresholding on colonies with dark centers.
Colonies with radial pigment texture that creates interior gaps.
Pre-measurement cleanup to ensure simply connected shapes.
- Consider Also:
MaskCloserfor bridging narrow gaps between fragments rather than filling holes within objects.MaskOpenerfor the opposite effect — removing thin connections between objects.
See also
How To: Refine Noisy Detection Boundaries for a walkthrough of refinement operations.
Methods
Initialize the filler and validate inputs.
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(structure: numpy.ndarray | None = None, origin: int = 0)[source]
Initialize the filler and validate inputs.
- Parameters:
structure (Optional[np.ndarray]) – Binary structuring element. Larger or more connected structures fill bigger holes and may reduce small-scale texture within colony masks. If provided, must be a binary array; otherwise a ValueError is raised.
origin (int) – Origin offset for the structuring element. Typically left at 0; changing it slightly alters how neighborhoods are centered, which may affect edge sharpness at boundaries.
- Raises:
ValueError – If
structureis provided and is not a binary mask.
- __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.