phenotypic.enhance.BM3DDenoiser#
- class phenotypic.enhance.BM3DDenoiser(sigma_psd: float = 0.02, block_size: int = 8, *, stage_arg: Literal['all_stages', 'hard_thresholding'] = 'all_stages', clip: bool = True)[source]
Bases:
ImageEnhancerDenoise
detect_matwith block-matching and 3D collaborative filtering.Groups similar image patches and filters them jointly in the transform domain, preserving fine colony details while removing structured noise patterns (scanner artifacts, systematic CCD noise, imaging hardware texture). Produces higher-quality results than simple Gaussian blur at significantly higher computational cost.
For algorithm details, see What Enhancement Actually Does.
- Parameters:
sigma_psd (float) – Noise standard deviation in [0, 1] normalized scale. Typical range: 0.01–0.05 for moderate noise, 0.05–0.15 for heavy noise. Too low preserves noise; too high removes colony texture. Default: 0.02.
block_size (int) – Block size for BM3D patch matching. Default: 8.
stage_arg (Literal['all_stages', 'hard_thresholding']) – Processing mode.
'all_stages'(default) applies both hard thresholding and Wiener filtering for highest quality;'hard_thresholding'runs only the first stage for faster processing.clip (bool) – Clip output to [0, 1]. Default:
True. Set toFalsewhen using with variance-stabilizing transforms (e.g., GAT).
- Returns:
Input image with
detect_matdenoised via BM3D collaborative filtering.rgbandgrayare unchanged.- Return type:
Image
- Best For:
Structured camera or scanner noise on plate images.
Low-light imaging where high ISO introduces patterned noise.
Preserving fine morphological features (wrinkles, satellite colonies) during denoising.
- Consider Also:
BilateralDenoisefor faster edge-preserving denoising when structured noise is not the primary concern.NonLocalMeansDenoiserfor patch-based denoising with lower computational overhead.VisuShrinkEnhancerfor fast wavelet denoising when speed matters more than quality.
References
[1] K. Dabov, A. Foi, V. Katkovnik, and K. Egiazarian, “Image denoising by sparse 3-D transform-domain collaborative filtering,” IEEE Trans. Image Process., vol. 16, no. 8, pp. 2080–2095, Aug. 2007.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of denoising pipelines on plate images. How To: Denoise Low-Light Images for BM3D and other denoising strategies on low-light plate images.
Methods
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(sigma_psd: float = 0.02, block_size: int = 8, *, stage_arg: Literal['all_stages', 'hard_thresholding'] = 'all_stages', clip: bool = True)[source]
- Parameters:
sigma_psd (float) – Noise level estimate in [0, 1] normalized scale. Start with 0.02-0.05 for typical scanner noise on plates (equivalent to σ=5-12 on 8-bit). Higher value -> more noise.
block_size (int) – Block size for BM3D denoising. Default is 8.
stage_arg (Literal["all_stages", "hard_thresholding"]) – Denoising stages to run. ‘all_stages’ gives best quality at the cost of speed; ‘hard_thresholding’ is faster and adequate for routine plate analysis.
clip (bool) – Whether to clip output to [0, 1] range. Default True. Set to False when using with variance-stabilizing transforms (e.g., GAT) that require preserving the original scale.
- __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.