phenotypic.enhance.RankMedianEnhancer#
- class phenotypic.enhance.RankMedianEnhancer(shape: str = 'square', width: int | None = None, shift_x=0, shift_y=0)[source]
Bases:
ImageEnhancerSuppress impulsive noise in
detect_matwith rank-based median filtering.Applies a local median using rank filters with a configurable structuring element shape and size. Effectively removes salt-and-pepper noise, dust speckles, and pixel-level artifacts while preserving colony boundaries when the footprint is smaller than the minimum colony diameter.
For algorithm details, see What Enhancement Actually Does.
- Parameters:
shape (str) – Footprint geometry.
'disk'for isotropic smoothing;'square'(default) to align with grid artifacts.width (int) – Footprint width in pixels. Set smaller than the minimum colony diameter to preserve colony edges.
None(default) derives a small value from image size.shift_x – Horizontal footprint offset. Typically 0. Default: 0.
shift_y – Vertical footprint offset. Typically 0. Default: 0.
- Returns:
Input image with
detect_matmedian-filtered.rgbandgrayare unchanged.- Return type:
Image
- Best For:
Salt-and-pepper or impulsive noise from sensor defects.
Dust speckles and pixel-level artifacts on scanned plates.
Grid-like imaging artifacts when using a
'square'footprint.
- Consider Also:
BilateralDenoisefor edge-preserving Gaussian noise removal without the intensity quantization of rank filters.NonLocalMeansDenoiserfor patch-based denoising that preserves texture better on noisy plates.GrayOpeningfor morphological artifact removal that does not require uint8 conversion.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of denoising pipelines on plate images.
Methods
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(shape: str = 'square', width: 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’.
width (int | None) – Neighborhood width in pixels. Set smaller than the minimum colony width to preserve colony edges; None chooses a small default based on image size.
shift_x (int) – Horizontal offset of the shape center to bias the neighborhood if artifacts are directional. Typically 0.
shift_y (int) – Vertical offset of the shape 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.
- 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.