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 (
str|None(default:None)) – The image layer insdataon which the enhance_contrast function will be applied. If not provided, the last image layer insdatais 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 indask.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 (
tuple[int,int,int,int] |None(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 thecrdis specified. Ignored ifcrdis None.scale_factors (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale.overwrite (
bool(default:False)) – If True overwrites the element if it already exists.
- Returns:
: An updated
sdataobject with the contrast enhanced image added as a new layer.- Raises:
ValueError – If the dimensions in
img_layerofsdatais 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.