StainFit.transform#
- StainFit.transform(sdata, *, image_key, 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 in
sdatato this reference.- Parameters:
- sdata
SpatialData SpatialData object containing the source image.
- image_key
str Key of the RGB image in
sdata.imagesto normalize.- scale
str|Literal['auto'] (default:'auto') Scale level to normalize.
"auto"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(default:None) Params matching this fit’s
method(mapping orNone).- image_key_added
str|None(default:None) Key for the written image when
inplace=True. IfNone,f"{image_key}_normalized"is used. Ignored wheninplace=False.- inplace
bool(default:True) If
True, 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(default:None) Dtype of the result. If
None, 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(default:None) Key of a tissue-label element in
sdata.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(default:True) If
True, 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.
- sdata
- Returns:
DataArray|None–Noneifinplace=True(the image is written), otherwise the lazy normalizedxarray.DataArray.