phenotypic.enhance.PhaseCongruencyEnhancer#

class phenotypic.enhance.PhaseCongruencyEnhancer(n_scale: int = 4, n_orient: int = 6, min_wavelength: float = 3.0, mult: float = 2.1, sigma_onf: float = 0.55, k: float = 2.0, cutoff: float = 0.5, g: float = 10.0, noise_method: float = -1, output: Literal['M', 'm', 'pc_sum'] = 'pc_sum')[source]

Bases: ImageEnhancer

Enhance colony edges in detect_mat with contrast-invariant phase congruency.

Detects features where Fourier components are maximally in phase, regardless of amplitude. This makes the response invariant to image contrast and illumination changes, making it ideal for plates with uneven lighting, scanner vignetting, or varying colony opacity.

For algorithm details, see What Enhancement Actually Does.

Parameters:
  • n_scale (int) – Number of wavelet scales. Typical range: 3–6. More scales capture a wider range of feature sizes. Default: 4.

  • n_orient (int) – Number of filter orientations. 6 gives 30-degree angular spacing. Default: 6.

  • min_wavelength (float) – Wavelength of smallest scale filter in pixels. Match to minimum expected colony edge width. Default: 3.0.

  • mult (float) – Scaling factor between successive wavelengths. Controls spectral overlap. Default: 2.1.

  • sigma_onf (float) – Log-Gabor bandwidth parameter. 0.55 gives ~2 octave bandwidth; 0.75 gives ~1 octave. Default: 0.55.

  • k (float) – Noise threshold multiplier. Higher values (5–20) increase noise rejection but may miss faint edges. Default: 2.0.

  • cutoff (float) – Frequency spread penalty threshold. Default: 0.5.

  • g (float) – Sigmoid sharpness for frequency spread weighting. Default: 10.

  • noise_method (float) – Noise estimation method. -1 (default) uses median-based estimation; -2 uses mode-based (Rayleigh); values >= 0 set a fixed noise threshold.

  • output (Literal['M', 'm', 'pc_sum']) – Result to store in detect_mat. 'pc_sum' (default) for scalar phase congruency, 'M' for edge strength, 'm' for corner strength.

Returns:

Input image with detect_mat replaced by the phase congruency map (clipped to [0, 1]). rgb and gray are unchanged.

Return type:

Image

Best For:
  • Colony boundaries independent of colony color or opacity.

  • Images with uneven illumination or scanner vignetting.

  • Faint colony edges that gradient-based methods miss.

  • Translucent or low-contrast colonies on agar.

Consider Also:
  • LaplaceEnhancer for simpler edge detection when illumination is uniform.

  • HessianFilter for multi-scale ridge and edge detection with blob sensitivity control.

  • UnsharpMask for edge sharpening that preserves the original intensity profile.

References

[1] P. Kovesi, “Image features from phase congruency,” Videre: J. Comput. Vis. Res., vol. 1, no. 3, pp. 1–26, 1999.

See also

Tutorial 3: Enhancing Before Detection for a visual walkthrough of contrast-invariant enhancement on plate images. What Enhancement Actually Does for background on phase congruency and the Local Energy Model.

Methods

__init__

Initialize phase congruency enhancer.

apply

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

widget

Return (and optionally display) the root widget.

__init__(n_scale: int = 4, n_orient: int = 6, min_wavelength: float = 3.0, mult: float = 2.1, sigma_onf: float = 0.55, k: float = 2.0, cutoff: float = 0.5, g: float = 10.0, noise_method: float = -1, output: Literal['M', 'm', 'pc_sum'] = 'pc_sum')[source]

Initialize phase congruency enhancer.

Parameters:
  • n_scale (int) – Number of wavelet scales. Range [3, 6] typical.

  • n_orient (int) – Number of filter orientations. 6 gives 30 degree spacing.

  • min_wavelength (float) – Wavelength of smallest scale filter in pixels. Should match minimum expected feature width (default 3.0).

  • mult (float) – Scaling factor between successive filter wavelengths. Controls spectral overlap between scales (default 2.1).

  • sigma_onf (float) – Ratio of Gaussian standard deviation to filter center frequency. Controls filter bandwidth. 0.55 gives ~2 octave bandwidth; 0.75 gives ~1 octave (default 0.55).

  • k (float) – Number of noise standard deviations for threshold. Higher values increase noise rejection (default 2.0, range [2, 20]).

  • cutoff (float) – Frequency spread measure below which PC values are penalized (default 0.5).

  • g (float) – Sharpness of sigmoid transition for frequency spread weighting (default 10.0).

  • noise_method (float) – Method for noise statistics estimation. -1 uses median of smallest scale responses (default), -2 uses mode (Rayleigh), values >= 0 are used as fixed noise threshold.

  • output (Literal['M', 'm', 'pc_sum']) – Which result to store in detect_mat. “pc_sum” for scalar phase congruency (default), “M” for edge strength, “m” for corners.

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