phenotypic.refine.WhiteTophat#
- class phenotypic.refine.WhiteTophat(shape: Literal['disk', 'square', 'diamond'] | numpy.ndarray = 'disk', width: int | None = None)[source]
Bases:
ObjectRefiner,FootprintMixinRemove small bright mask structures using white tophat subtraction.
Applies a white tophat transform to the binary mask to detect small bright features (glare bridges, dust speckles, thin connections) and subtracts them. Produces cleaner, more compact masks that better match colony boundaries under uneven illumination.
- Parameters:
shape (Literal['disk', 'square', 'diamond'] | np.ndarray) – Structuring element shape.
"disk"preserves round features,"square"is more aggressive along axes,"diamond"provides a compromise. A NumPy array provides a custom element. Default:"disk".width (int | None) – Footprint width in pixels. Larger values remove broader bright features but risk shrinking thin colony appendages.
Noneauto-scales to ~0.4% of the smallest image dimension. Default: None.
- Returns:
Input image with
objmaskupdated by subtracting the white tophat result.- Return type:
Image
- Best For:
Reducing glare-induced bridges between neighboring colonies.
Removing bright speckles or dust embedded in masks after thresholding.
Cleaning up thin bright connections that inflate colony perimeters.
- Consider Also:
MaskOpenerfor general morphological opening that removes thin protrusions without tophat detection.SmallObjectRemoverwhen small artifacts are entire disconnected objects rather than thin bridges.GMMCoreExtractorfor intensity-based core extraction when halos are the primary artifact.
See also
How To: Refine Noisy Detection Boundaries for tophat-based cleanup workflows. Refinement Strategies for a comparison of morphological refinement methods.
Methods
Represents a structural element used to analyze and process images, specifically useful for microbial colony analysis on solid media agar.
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(shape: Literal['disk', 'square', 'diamond'] | numpy.ndarray = 'disk', width: int | None = None)[source]
Represents a structural element used to analyze and process images, specifically useful for microbial colony analysis on solid media agar.
The class encapsulates the shape and size of the structural element. Structural elements are commonly used in morphological image processing tasks such as dilations, erosions, opening, and closing. These operations can enhance or isolate features of microbe colonies on agar plates, such as determining colony size, spacing, or detecting connections between colonies.
- shape
Defines the shape of the structural element. Choosing “disk” may help preserve the rounded geometry of typical microbial colonies. “Square” and “diamond” shapes may be more useful for colonies that form irregular or grid-based patterns. Supplying a custom numpy array (np.ndarray) allows for complete customization of the structural element, which could be beneficial for non- standard colony morphologies.
- Type:
Literal[“disk”, “square”, “diamond”] | np.ndarray
- width
Specifies the size of the structural element by defining the width. Larger widths will create structural elements that can encompass larger colonies or areas of colonies, potentially aiding in operations designed to merge close colonies. Smaller widths will result in more localized structural elements, which can preserve fine details and delineate smaller colonies. A None value assumes a default or minimal size.
- Type:
int | None
- __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.