phenotypic.enhance.LaplaceEnhancer#
- class phenotypic.enhance.LaplaceEnhancer(kernel_size: int | None = 3, mask: numpy.ndarray | None = None)[source]
Bases:
ImageEnhancerEnhance colony edges in
detect_matwith a Laplacian operator.Applies a discrete Laplacian that responds to rapid intensity changes, highlighting colony margins and ring-like features such as swarming fronts. Useful as a preprocessing step for contour detection, watershed seeding, or separating touching colonies.
For algorithm details, see What Enhancement Actually Does.
- Parameters:
kernel_size (Optional[int]) – Size of the Laplacian kernel. Smaller values (3) capture fine edges but amplify noise; larger values (5–7) smooth noise and emphasize broader boundaries. Default: 3.
mask (Optional[np.ndarray]) – Boolean or 0/1 mask to restrict processing to regions of interest (e.g., the circular plate area).
None(default) processes the full image.
- Returns:
Input image with
detect_matreplaced by the Laplacian edge response.rgbandgrayare unchanged.- Return type:
Image
- Best For:
Emphasizing colony edges before edge-based segmentation.
Detecting ring patterns around colonies for swarming phenotyping.
Generating watershed seeds by highlighting boundary regions.
- Consider Also:
HessianFilterfor multi-scale edge and ridge detection with more tuning control.UnsharpMaskfor edge enhancement that retains the original intensity profile.PhaseCongruencyEnhancerfor contrast-invariant edge detection under uneven illumination.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of edge enhancement on plate images.
Methods
Applies the operation to an image, either in-place or on a copy.
Return (and optionally display) the root widget.
- __init__(kernel_size: int | None = 3, mask: numpy.ndarray | None = None)[source]
- Parameters:
kernel_size (Optional[int]) – Controls the edge scale. Smaller values pick up fine edges but increase noise sensitivity; larger values smooth noise and emphasize broader boundaries.
mask (Optional[np.ndarray]) – Boolean/0-1 mask to limit processing to regions of interest (e.g., the circular plate), reducing artifacts from dish rims or labels.
- __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.