phenotypic.enhance.GaussianBlur#
- class phenotypic.enhance.GaussianBlur(sigma: int = 2, *, mode: str = 'reflect', cval=0.0, truncate: float = 4.0)[source]#
Bases:
ImageEnhancerGaussian blur smoothing for plate images.
Applies Gaussian smoothing to reduce high-frequency noise and minor texture on agar plates (e.g., scanner noise, agar granularity, condensation speckle). This can make colony boundaries more coherent and reduce false edges before edge detection or thresholding.
Use cases (agar plates): - Suppress “salt-and-pepper” noise and minor agar texture so thresholding is
driven by colony signal rather than noise.
Pre-filter before SobelFilter or Laplacian to avoid amplifying noise.
Slightly smooth within colonies to make segmentation more compact.
Tuning and effects: - sigma: Controls blur strength. Choose below the typical colony radius to
avoid merging close colonies. Too large sigma will wash out small colonies and narrow gaps between neighbors.
mode/cval: Define how edges are handled. For plates, ‘reflect’ usually avoids artificial dark/bright rims. ‘constant’ with a neutral cval may be useful for cropped regions.
truncate: Larger values include more of the Gaussian tail (slightly slower) with subtle effect on smoothness near edges.
Caveats: - Excessive blur merges adjacent colonies and reduces edge sharpness. - Do not rely on blur to fix illumination gradients; prefer background
subtraction (e.g., GaussianSubtract or RollingBallRemoveBG).
- truncate#
Radius of kernel in standard deviations; kernel is truncated beyond this distance.
- Type:
Methods
Applies the operation to an image, either in-place or on a copy.
Drop references to the UI widgets.
Push internal state into widgets.
Return (and optionally display) the root widget.
- __init__(sigma: int = 2, *, mode: str = 'reflect', cval=0.0, truncate: float = 4.0)[source]#
- Parameters:
sigma (int) – Blur strength; start near 1–3 for high-resolution scans. Keep below the colony radius 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.
- widget(image: Image | None = None, show: bool = False) Widget#
Return (and optionally display) the root widget.
- Parameters:
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.