phenotypic.enhance.BayesShrinkEnhancer#
- class phenotypic.enhance.BayesShrinkEnhancer(sigma: float | None = None, wavelet: str = 'db2', mode: Literal['soft', 'hard'] = 'soft', wavelet_levels: int | None = None, clip: bool = True)[source]
Bases:
ImageEnhancerDenoise
detect_matwith adaptive BayesShrink wavelet thresholding.Applies wavelet-domain denoising with per-subband adaptive thresholds computed from local statistics. Preserves more fine detail than
VisuShrinkEnhancerby denoising aggressively only where noise is high and gently where signal dominates.For algorithm details, see What Enhancement Actually Does.
- Parameters:
sigma (float | None) – Noise standard deviation in [0, 1] scale.
None(default) auto-estimates via MAD. Typical range: 0.01–0.05 for moderate scanner/camera noise. Accurate estimation improves adaptive threshold quality.wavelet (str) – Wavelet family.
'db2'(default) balances smoothness and locality;'db4'preserves finer details. Must be orthogonal.mode (Literal['soft', 'hard']) – Thresholding mode.
'soft'(default) produces smoother results;'hard'preserves edges more aggressively.wavelet_levels (int | None) – Decomposition depth.
None(default) uses max-3 automatically. Higher values allow finer noise/signal separation.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 adaptive wavelet thresholding.rgbandgrayare unchanged.- Return type:
Image
- Best For:
Images with spatially varying noise from uneven illumination.
Preserving colony texture and internal morphology during denoising.
Scanner noise and camera artifacts on plates where fine detail matters for downstream measurement.
Pre-filtering before feature extraction or texture analysis.
- Consider Also:
VisuShrinkEnhancerfor faster denoising with a universal threshold when spatial noise uniformity is acceptable.BM3DDenoiserfor state-of-the-art denoising of structured noise patterns.BilateralDenoisefor edge-preserving smoothing without wavelet decomposition.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of enhancement pipelines on plate images. What Enhancement Actually Does for background on wavelet denoising and threshold selection strategies.
Methods
Initialize BayesShrink adaptive wavelet denoiser.
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(sigma: float | None = None, wavelet: str = 'db2', mode: Literal['soft', 'hard'] = 'soft', wavelet_levels: int | None = None, clip: bool = True)[source]
Initialize BayesShrink adaptive wavelet denoiser.
- Parameters:
sigma (float | None) – Noise standard deviation in [0, 1] scale. None (default) auto-estimates. More accurate sigma improves adaptive thresholding quality. Typical: 0.01-0.05 for moderate noise.
wavelet (str) – Wavelet type. ‘db2’ (default) is general-purpose. ‘db4’ for finer details, ‘sym2’ for symmetric filters.
mode (Literal['soft', 'hard']) – ‘soft’ (default) for smoother denoising, ‘hard’ for sharper edges with possible noise residue.
wavelet_levels (int | None) – Decomposition depth. None (default) uses max-3. Increase for very noisy images.
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.