phenotypic.enhance.HessianFilter#

class phenotypic.enhance.HessianFilter(sigmas: Iterable[float] = (1, 2, 3), alpha: float = 0.5, beta: float = 0.5, gamma: float = 15, black_ridges: bool = False, mode: str = 'reflect', cval: float = 0)[source]

Bases: ImageEnhancer

Enhance edges and ridge-like structures via multi-scale Hessian filtering.

Computes eigenvalue-based Hessian responses across multiple scales to highlight colony boundaries, thin filamentous structures, and ridge-like features in detect_mat. Multi-scale analysis makes detection robust across varying colony sizes and morphologies.

For algorithm details, see What Enhancement Actually Does.

Parameters:
  • sigmas (Iterable[float]) – Sequence of standard deviations for Gaussian derivatives. Smaller values detect finer edges; larger values detect broader structures. Typical range: (1, 2, 3) to (1, 5). Default: (1, 2, 3).

  • alpha (float) – Sensitivity to plate-like structure deviations. Lower values are more permissive. Typical range: 0.1–1.0. Default: 0.5.

  • beta (float) – Sensitivity to blob-like structure deviations. Lower values are more permissive. Typical range: 0.1–1.0. Default: 0.5.

  • gamma (float) – Background suppression threshold. Larger values suppress low-curvature regions (agar background) more aggressively. Typical range: 10–20. Default: 15.

  • black_ridges (bool) – If True, detect dark ridges on bright background. If False (default), detect bright ridges on dark background.

  • mode (str) – Boundary handling. Accepted values: 'reflect', 'constant', 'nearest', 'mirror', 'wrap'. Default: 'reflect'.

  • cval (float) – Fill value when mode='constant'. Default: 0.

Returns:

Input image with detect_mat replaced by the Hessian ridge response map. rgb and gray are unchanged.

Return type:

Image

Best For:
  • Sharp boundaries between colonies and agar background.

  • Thin or elongated structures (filaments, branching) with poor contrast.

  • Size-invariant colony edge enhancement before thresholding.

  • Textured colonies or biofilms with complex internal structure.

Consider Also:
  • SatoRidgeFilter for continuous tube-like structures where Hessian eigenvalue ratios provide cleaner ridge responses.

  • MeijeringRidgeFilter for very fine neurite-like filaments.

  • LaplaceEnhancer for simpler second-derivative edge detection without multi-scale analysis.

See also

Tutorial 3: Enhancing Before Detection for a visual walkthrough of ridge and edge enhancement on plate images. What Enhancement Actually Does for background on Hessian-based structure detection.

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__(sigmas: Iterable[float] = (1, 2, 3), alpha: float = 0.5, beta: float = 0.5, gamma: float = 15, black_ridges: bool = False, mode: str = 'reflect', cval: float = 0)[source]
Parameters:
  • sigmas (tuple | list) – Sequence of standard deviations for Gaussian derivatives. Smaller values detect finer edges, larger values detect thicker structures. Default (1, 2, 3).

  • alpha (float) – Sensitivity to plate-like structure deviations. Lower values are more permissive. Range: 0 to 1. Default 0.5.

  • beta (float) – Sensitivity to blob-like structure deviations. Lower values are more permissive. Range: 0 to 1. Default 0.5.

  • gamma (float) – Threshold for background suppression. Larger values suppress low-curvature regions (agar background) more aggressively. Default 15.

  • black_ridges (bool) – If True, detect dark ridges (colonies) on bright background. If False, detect bright ridges on dark background. For agar plates with dark colonies on light background, use True. Default False.

  • mode (str) – Boundary handling mode (‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’). Default ‘reflect’.

  • cval (float) – Constant value used if mode=’constant’. Default 0.

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