squidpy.experimental.im.normalize_stains
- squidpy.experimental.im.normalize_stains(sdata, image_key, reference, *, scale='auto', method_params=None, image_key_added=None, inplace=True, output_dtype=None, tissue_mask_key=None, preserve_background=True)[source]
Normalize an image to a fitted stain reference.
- Parameters:
sdata (
SpatialData) – SpatialData object containing the source image.image_key (
str) – Key of the RGB image insdata.imagesto normalize.reference (
StainReference) – AStainReferencefitted withfit_stain_reference(). Dispatch is onreference.method.scale (
Union[str,Literal['auto']]) – Scale level to normalize."auto"(default) uses the finest level so the result is not downsampled; source statistics are reduced lazily so memory stays bounded.method_params (
ReinhardParams|MacenkoParams|VahadaneParams|Mapping[str,Any] |None) – Params matchingreference.method(instance, mapping, orNone).image_key_added (
str|None) – Key for the written image wheninplace=True. IfNone(default),f"{image_key}_normalized"is used. Ignored wheninplace=False.inplace (
bool) – IfTrue(default), write the normalized image tosdata.images[image_key_added](rebuilding the pyramid for multiscale sources, preserving transforms) and returnNone; raises if the key already exists. IfFalse, leavesdatauntouched and return the lazy normalizedDataArray.output_dtype (
DTypeLike|None) – Dtype of the result. IfNone(default), the source image’s dtype is used. The reconstruction is clipped to that dtype’s valid range and rounded (for integer dtypes) at the write boundary.tissue_mask_key (
str|None) – Key of a tissue-label element insdata.labelsrestricting the source statistics to tissue pixels. As forfit_stain_reference(), a tissue mask is required (defaults tof"{image_key}_tissue"; raises if missing).preserve_background (
bool) – IfTrue(default), non-tissue (background) pixels are passed through unchanged from the source image, so the normalization recolours only tissue. The colour map is a global linear transform that would otherwise tint background/white pixels. SetFalsefor full-frame normalization.
- Return type:
- Returns:
Noneifinplace=True(the image is written), otherwise the lazy normalizedxarray.DataArray.