phenotypic.enhance.WhiteTophatEnhancer#
- class phenotypic.enhance.WhiteTophatEnhancer(shape: str = 'diamond', radius: int | None = None)[source]#
Bases:
ImageEnhancerWhite top-hat transform to suppress small bright structures.
Computes the white top-hat (original minus opening) using a structuring element, then subtracts it from the image here (i.e., remove small bright blobs). In agar plate colony images, this helps reduce bright specks from dust, glare, or condensation, making colonies stand out against a smoother background.
Use cases (agar plates): - Remove small bright artifacts that can be mistaken for tiny colonies. - Reduce glare highlights on shiny plates before thresholding.
Tuning and effects: - shape: The morphology footprint geometry. ‘diamond’ or ‘disk’ are good
isotropic choices on plates; ‘square’ can align with pixel grids.
radius: Sets the maximum size of bright features to remove. Choose slightly smaller than the minimum colony radius so real colonies are preserved.
Caveats: - If radius is too large, real small colonies will be attenuated. - Operates on bright features; for dark colonies on bright agar, it primarily
removes bright noise rather than enhancing the colonies themselves.
- radius#
Footprint radius in pixels; if None, a small default is derived from the image size.
- Type:
int | None
Methods
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__(shape: str = 'diamond', radius: int | None = None)[source]#
- Parameters:
shape (str) – Footprint geometry controlling which bright features are removed. ‘diamond’ or ‘disk’ provide isotropic behavior on plates; ‘square’ can align with sensor grid artifacts. Advanced: ‘sphere’ or ‘cube’ for volumetric data.
radius (int | None) – Maximum bright-object size (in pixels) targeted for removal. Set slightly smaller than the smallest colonies to avoid suppressing real colonies. None picks a small default based on image dimensions.
- __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.