phenotypic.enhance.CLAHE#
- class phenotypic.enhance.CLAHE(kernel_size: int | None = None, clip_limit: float = 0.01)[source]
Bases:
ImageEnhancerBoost local contrast in detect_mat using adaptive histogram equalization.
Divides detect_mat into tiles and equalizes the histogram within each tile, with a clip limit that prevents excessive noise amplification. Faint colonies become more visible and easier to threshold, even when illumination varies across the plate.
For a discussion of contrast enhancement strategies, see What Enhancement Actually Does.
- Parameters:
kernel_size (int | None) – Tile size for local equalization. Smaller tiles reveal tiny colonies but amplify agar texture; larger tiles produce smoother results.
Noneauto-selects based on image size (typically min(height, width) / 15). Default:None.clip_limit (float) – Maximum local contrast amplification. Typical range: 0.005–0.05. Lower values suppress noise; higher values make faint colonies stand out more. Default: 0.01.
- Returns:
Input image with
detect_matcontrast-enhanced.rgbandgrayare unchanged.- Return type:
Image
- Raises:
ValueError – If the detect_mat value range is invalid.
- Best For:
Plates with faint or translucent colonies that blend into agar.
Uneven illumination (vignetting, shadows from plate lids).
Pre-conditioning before global thresholding (Otsu, Triangle).
Early time-point plates where colonies are barely visible.
- Consider Also:
ContrastStretchingfor a simpler global contrast adjustment when illumination is already uniform.HomomorphicFilterwhen the primary problem is a large-scale illumination gradient rather than local contrast.UnsharpMaskwhen edges need sharpening rather than contrast boosting.
References
[1] S. M. Pizer et al., “Adaptive histogram equalization and its variations,” Computer Vision, Graphics, and Image Processing, vol. 39, no. 3, pp. 355–368, Sep. 1987.
See also
Tutorial 3: Enhancing Before Detection for a visual walkthrough of CLAHE before detection. How To: Enhance Low-Contrast Images for a comparison of contrast enhancement methods.
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 = None, clip_limit: float = 0.01)[source]
- Parameters:
kernel_size (int | None) – Tile size for adaptive equalization. Smaller tiles enhance very local contrast (revealing tiny colonies) but can amplify agar texture; larger tiles produce smoother, gentler effects. None selects an automatic size based on image dimensions.
clip_limit (float) – Maximum local contrast amplification. Lower values reduce noise/halo amplification; higher values make faint colonies stand out more but can emphasize dust or condensation.
- __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.