phenotypic.enhance.UnsharpMask#

class phenotypic.enhance.UnsharpMask(radius: float = 2.0, amount: float = 1.0, preserve_range: bool = False, n_iter: int = 1)[source]

Bases: ImageEnhancer

Sharpen colony edges in detect_mat with unsharp masking.

Subtracts a Gaussian-blurred copy from the original and scales the difference to emphasize high-contrast boundaries. Makes soft or indistinct colony edges more pronounced, improving thresholding and edge-detection accuracy.

For algorithm details, see What Enhancement Actually Does.

Parameters:
  • radius (float) – Standard deviation of the Gaussian blur in pixels. Controls the scale of features enhanced. Small values (0.5–2.0) sharpen fine details; larger values (5–15) enhance broader features. Default: 2.0.

  • amount (float) – Multiplier for the sharpening effect. Low values (0.3–0.7) produce subtle enhancement; standard values (1.0–1.5) give moderate sharpening; high values (2.0+) create aggressive enhancement with risk of halo artifacts. Default: 1.0.

  • preserve_range (bool) – Preserve the original pixel value range. Default: False.

  • n_iter (int) – Number of successive sharpening passes. Multiple passes compound the effect. Typical range: 1–3. Default: 1.

Returns:

Input image with detect_mat sharpened via unsharp masking. rgb and gray are unchanged.

Return type:

Image

Best For:
  • Low-contrast colonies with soft, gradual edges (translucent growth).

  • Dense plates where colonies blend into background.

  • Pre-threshold sharpening to improve segmentation accuracy.

  • Slight scanner or lens blur that softens colony boundaries.

Consider Also:
  • BilateralDenoise for denoising before sharpening on grainy images to avoid amplifying noise.

  • LaplaceEnhancer for second-derivative edge detection that replaces rather than enhances the intensity profile.

  • PhaseCongruencyEnhancer for contrast-invariant edge detection under uneven illumination.

See also

Tutorial 3: Enhancing Before Detection for a visual walkthrough of edge sharpening on plate images. What Enhancement Actually Does for background on unsharp masking and sharpening strategies.

Methods

__init__

apply

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

widget

Return (and optionally display) the root widget.

__init__(radius: float = 2.0, amount: float = 1.0, preserve_range: bool = False, n_iter: int = 1)[source]
Parameters:
  • radius (float) – Standard deviation (sigma) of the Gaussian blur in pixels. Defines the scale of features to enhance. Small values (0.5–2) sharpen fine details (thin colony edges, small morphologies); larger values (5–15) enhance broad features (large colonies, colony-background separation). Must be > 0. For fungal colonies, keep below the typical colony width to avoid merging adjacent colonies. Recommended: 2.0–3.0 for general-purpose use, 1.0 for high-density plates, 5.0+ for emphasizing large-scale features on low-resolution images.

  • amount (float) – Amplification factor for the sharpening effect. Controls how much the edge enhancement contributes to the output. Typical range: 0.3–2.5. Low values (0.3–0.7) produce subtle enhancement suitable for noisy images; standard values (1.0–1.5) give balanced sharpening; high values (2.0+) create aggressive enhancement for very low-contrast colonies. Can be negative to produce blurring instead. Excessive amounts risk visible artifacts and noise amplification.

  • preserve_range (bool) – If False (default), output may be rescaled if necessary. If True, the original range of input values is preserved. Keep as False for consistency with other enhancers.

  • n_iter (int) – Number of successive unsharp mask passes to apply. Must be >= 1. One pass (default) applies the filter once. Multiple passes (2+) compound the sharpening effect for progressively more aggressive enhancement, but at increased risk of noise amplification and halo artifacts.

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