phenotypic.enhance.RankMedianEnhancer#
- class phenotypic.enhance.RankMedianEnhancer(shape: str = 'square', radius: int | None = None, shift_x=0, shift_y=0)[source]#
Bases:
ImageEnhancerRank-based median filtering with configurable footprint.
Applies a local median using rank filters with a user-defined footprint shape and radius. For agar plate colony images, this enables targeted suppression of impulsive noise while tailoring the spatial scale to colony size and shape, offering more control than a default median.
Use cases (agar plates): - Denoise while preserving colony boundaries by matching the footprint radius
to be smaller than colony diameters.
Use anisotropic or non-circular footprints (e.g., squares) for grid-like artifacts from imaging hardware.
Tuning and effects: - shape: Choose ‘disk’ for circular isotropic smoothing on plates;
‘square’ or ‘cube’ can align with grid artifacts; ‘ball’ for 3D stacks.
radius: Controls neighborhood size. Larger radii remove more noise but can erode small colonies and close tight gaps.
shift_x/shift_y: Offset the footprint center to bias the neighborhood if imaging introduces directional streaks; typically left at 0.
Caveats: - Very large footprints may over-smooth and merge nearby colonies. - Rank filters operate on uint8 here; intensity scaling occurs internally.
Ensure consistency if comparing raw intensities elsewhere.
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 = 'square', radius: int | None = None, shift_x=0, shift_y=0)[source]#
- Parameters:
shape (str) – Geometry of the neighborhood. Use ‘disk’ for isotropic smoothing on plates; ‘square’ to align with grid noise; ‘sphere’/’cube’ for 3D contexts. Default ‘square’.
radius (int | None) – Neighborhood radius in pixels. Set smaller than the minimum colony radius to preserve colony edges; None chooses a small default based on image size.
shift_x (int) – Horizontal offset of the footprint center to bias the neighborhood if artifacts are directional. Typically 0.
shift_y (int) – Vertical offset of the footprint center. Typically 0.
- __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.