sparrow.im.enhance_contrast

sparrow.im.enhance_contrast#

sparrow.im.enhance_contrast(sdata, img_layer=None, contrast_clip=3.5, chunks=10000, depth=3000, output_layer='clahe', crd=None, to_coordinate_system='global', scale_factors=None, overwrite=False)#

Enhance the contrast of an image in a SpatialData object.

Contrast Limited Adaptive Histogram Equalization (CLAHE) is used. Compatibility with image layers that have either two or three spatial dimensions (c, (z), y, x).

Parameters:
  • sdata (SpatialData) – The SpatialData object containing the image to enhance.

  • img_layer (Optional[str] (default: None)) – The image layer in sdata on which the enhance_contrast function will be applied. If not provided, the last image layer in sdata is used.

  • contrast_clip (float | list[float] (default: 3.5)) – The clip limit for the CLAHE algorithm. Higher values result in stronger contrast enhancement but also stronger noise amplification. If provided as a list, the length must match the number of channels, as the parameter will be used to process the different channels.

  • chunks (str | tuple[int, ...] | int | None (default: 10000)) – Specification for rechunking the data before applying the function.

  • depth (tuple[int, ...] | dict[int, int] | int (default: 3000)) – The overlapping depth used in dask.array.map_overlap. If specified as a tuple or dict, it contains the depth used in ‘y’ and ‘x’ dimension.

  • output_layer (str (default: 'clahe')) – The name of the image layer where the enhanced image will be stored. The default value is “clahe”.

  • crd (Optional[tuple[int, int, int, int]] (default: None)) – The coordinates specifying the region of the image to be processed. Defines the bounds (x_min, x_max, y_min, y_max).

  • to_coordinate_system (str (default: 'global')) – The coordinate system to which the crd is specified. Ignored if crd is None.

  • scale_factors (Optional[Sequence[Union[dict[str, int], int]]] (default: None)) – Scale factors to apply for multiscale.

  • overwrite (bool (default: False)) – If True overwrites the element if it already exists.

Returns:

: An updated sdata object with the contrast enhanced image added as a new layer.

Raises:

ValueError – If the dimensions in img_layer of sdata is not equal to (c,(z),y,x)

Notes

CLAHE is applied to each channel and z-stack (if the image is 3D) of the image separately.