phenotypic.correction.BayesShrinkCorrector#
- class phenotypic.correction.BayesShrinkCorrector(sigma: float | None = None, wavelet: str = 'db2', mode: Literal['soft', 'hard'] = 'soft', wavelet_levels: int | None = None, convert2ycbcr: bool = True)[source]
Bases:
ImageCorrectorDenoise all image components using adaptive BayesShrink wavelet thresholding.
Apply subband-adaptive wavelet denoising to RGB (if present), grayscale, and detection matrix simultaneously. BayesShrink estimates a separate threshold for each wavelet subband, preserving fine colony detail while suppressing noise more selectively than a universal threshold.
For algorithm details, see What Enhancement Actually Does.
- Parameters:
sigma (float | None) – Noise standard deviation.
Noneauto-estimates from the finest wavelet subband. Typical range: 0.01–0.1 for normalized images. Default:None.wavelet (str) – Wavelet family name.
'db2'balances smoothness and locality;'db4'preserves finer spatial detail. Default:'db2'.mode (Literal['soft', 'hard']) – Thresholding mode.
'soft'produces smoother results;'hard'retains sharper edges with possible noise residue. Default:'soft'.wavelet_levels (int | None) – Number of decomposition levels.
Noneuses the maximum minus three (automatic). Default:None.convert2ycbcr (bool) – Denoise RGB in YCbCr space so luminance and chrominance are handled separately, preserving colony color. Only applies when RGB data is present. Default:
True.
- Returns:
Input image with all components (RGB, gray, detect_mat) transformed by adaptive wavelet denoising.
- Return type:
Image
- Best For:
Plates imaged with aging or high-ISO cameras that introduce spatially varying sensor noise.
RGB plate scans destined for publication where color fidelity and fine detail must be preserved.
Pre-processing before multi-channel feature extraction (color composition and morphology).
- Consider Also:
VisuShrinkCorrectorwhen a faster, simpler universal threshold is acceptable.StableDenoisefor variance-stabilized BM3D denoising of grayscale channels with Poisson-Gaussian noise.BayesShrinkEnhancerwhen only the detection matrix should be denoised (non-destructive to RGB and gray).
References
[1] S. G. Chang, B. Yu, and M. Vetterli, “Adaptive wavelet thresholding for image denoising and compression,” IEEE Trans. Image Process., vol. 9, no. 9, pp. 1532–1546, Sep. 2000.
See also
/how_to/notebooks/correct_color_cast for a walkthrough of denoising plate images before color analysis.
Methods
Initialize BayesShrink adaptive corrector for all image components.
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, convert2ycbcr: bool = True)[source]
Initialize BayesShrink adaptive corrector for all image components.
- Parameters:
sigma (float | None) – Noise level. None (default) auto-estimates. BayesShrink benefits from accurate sigma for optimal adaptive thresholding. Test explicit values if auto-estimation seems off.
wavelet (str) – Wavelet type. ‘db2’ (default) is general-purpose. ‘db4’ for finer detail preservation.
mode (Literal['soft', 'hard']) – ‘soft’ (default) for smoothness, ‘hard’ for sharper edges with possible noise residue.
wavelet_levels (int | None) – Levels. None = max-3 (automatic).
convert2ycbcr (bool) – Denoise RGB in YCbCr (True, default) for better color preservation. Only applies when RGB exists.
- __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: Image, inplace: bool = False) Image
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.