phenotypic.enhance.VisuShrinkEnhancer#

class phenotypic.enhance.VisuShrinkEnhancer(sigma: float | None = None, wavelet: str = 'db2', mode: Literal['soft', 'hard'] = 'soft', wavelet_levels: int | None = None, clip: bool = True)[source]

Bases: ImageEnhancer

Denoise detect_mat with universal VisuShrink wavelet thresholding.

Applies wavelet-domain denoising with a single universal threshold across all subbands, designed to remove all Gaussian noise with high probability. Faster than BayesShrinkEnhancer but may over-smooth regions with low noise. Preserves colony edges better than Gaussian blur.

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. Too high causes over-smoothing.

  • wavelet (str) – Wavelet family. 'db2' (default) balances smoothness and locality; 'db4' captures more detail. Must be orthogonal.

  • mode (Literal['soft', 'hard']) – Thresholding mode. 'soft' (default) produces smoother results for additive noise; 'hard' preserves edges more.

  • wavelet_levels (int | None) – Decomposition depth. None (default) uses max-3 automatically. Higher values give finer denoising.

  • clip (bool) – Clip output to [0, 1]. Default: True. Set to False when using with variance-stabilizing transforms (e.g., GAT).

Returns:

Input image with detect_mat denoised via universal wavelet thresholding. rgb and gray are unchanged.

Return type:

Image

Best For:
  • Scanner banding and flatbed scanner noise removal.

  • High-ISO camera images where colony boundaries must remain sharp.

  • Agar granularity and condensation speckle suppression before detection.

  • Pre-filtering before edge detection to avoid noise amplification.

Consider Also:
  • BayesShrinkEnhancer for adaptive thresholding that preserves more detail in regions with varying noise levels.

  • BM3DDenoiser for state-of-the-art structured noise removal at higher computational cost.

  • BilateralDenoise for edge-preserving smoothing without wavelet decomposition.

References

[1] D. L. Donoho and I. M. Johnstone, “Ideal spatial adaptation by wavelet shrinkage,” Biometrika, vol. 81, no. 3, pp. 425–455, Sep. 1994.

See also

Tutorial 3: Enhancing Before Detection for a visual walkthrough of denoising pipelines on plate images. What Enhancement Actually Does for background on wavelet denoising and threshold selection strategies.

Methods

__init__

Initialize VisuShrink wavelet denoiser.

apply

Applies the operation to an image, either in-place or on a copy.

widget

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 VisuShrink wavelet denoiser.

Parameters:
  • sigma (float | None) – Noise standard deviation in [0, 1] scale. None (default) auto-estimates via median absolute deviation (MAD). For reference: 8-bit noise σ=10/255 ≈ 0.04 in normalized scale. Typical values: 0.01-0.05 for moderate scanner/camera noise. Start with auto-estimation, then tune if needed.

  • wavelet (str) – Wavelet type from PyWavelets. ‘db2’ (default) is a good general choice. ‘db4’ for more detail, ‘sym2’ for symmetry. Must be orthogonal (db*, sym*) for proper noise handling.

  • mode (Literal['soft', 'hard']) – Threshold type. ‘soft’ (default) produces smoother results for additive noise. ‘hard’ preserves edges more but may leave noise artifacts.

  • wavelet_levels (int | None) – Decomposition depth. None (default) uses max-3 automatically. Higher = finer denoising, slower.

  • 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.