phenotypic.enhance.GaussianBlur#
- class phenotypic.enhance.GaussianBlur(sigma: float = 2.0, *, mode: str = 'reflect', cval=0.0, truncate: float = 4.0)[source]
Bases:
ImageEnhancerSmooth noise in detect_mat using isotropic Gaussian convolution.
Reduces high-frequency noise, scanner artifacts, and minor agar texture so that downstream thresholding responds to colony signal rather than noise. Colony edges become more coherent at the cost of some spatial sharpness.
For a comparison of denoising approaches, see What Enhancement Actually Does.
- Parameters:
sigma (float) – Standard deviation of the Gaussian kernel in pixels. Controls blur strength. Typical range: 0.5–5.0. Keep below the smallest colony radius to avoid merging adjacent colonies. Default: 2.0.
mode (str) – Boundary handling. Accepted values:
'reflect','constant','nearest'. Default:'reflect'.cval – Fill value when
mode='constant'. Default: 0.0.truncate (float) – Kernel extent in standard deviations. Rarely needs adjustment. Default: 4.0.
- Returns:
Input image with
detect_matsmoothed by the Gaussian kernel.rgbandgrayare unchanged.- Return type:
Image
- Raises:
ValueError – If
modeis not one of the accepted values.
- Best For:
Plates with visible scanner noise or agar granularity.
Pre-filtering before edge-based detectors (Sobel, Canny).
Quick preprocessing when speed matters more than edge preservation.
- Consider Also:
MedianFilterwhen salt-and-pepper noise dominates and edge preservation is important.BilateralDenoisefor smoothing within regions while keeping colony boundaries sharp.StableDenoisefor highest-quality BM3D denoising on critical experiments.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of enhancement before detection. How To: Denoise Low-Light Images for a comparison of denoising methods.
Methods
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(sigma: float = 2.0, *, mode: str = 'reflect', cval=0.0, truncate: float = 4.0)[source]
- Parameters:
sigma (float) – Blur strength; start near 1–3 for high-resolution scans. Keep below the colony width to avoid merging colonies.
mode (str) – Boundary handling. ‘reflect’ is a safe default for plates; ‘constant’ may require setting cval close to background.
cval (float) – Constant fill value when mode=’constant’.
truncate (float) – Kernel extent in standard deviations. Rarely needs adjustment; larger values slightly widen the effective kernel.
- __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.