StainFit.decompose#
- StainFit.decompose(sdata, *, image_key, scale='auto', image_key_added=None, inplace=True, output_dtype=<class 'numpy.float16'>, include_residual=True)[source]#
Decompose an image in
sdatainto separate per-stain concentration maps.Requires a decomposition reference (
method="macenko"or"vahadane"): its stain matrix and white point are projected onto the image as-is, so this reference is the provenance record of how the maps were produced.- Parameters:
- sdata
SpatialData The SpatialData object and the RGB image key to decompose.
- image_key
str The SpatialData object and the RGB image key to decompose.
- scale
str|Literal['auto'] (default:'auto') Scale level to decompose.
"auto"uses the finest level.- image_key_added
str|None(default:None) Key prefix for the written images when
inplace=True. IfNone,image_keyis used, so each stain is written as its own single-channel imagesdata.images[f"{image_key}_{stain}"](e.g.f"{image_key}_hematoxylin"). Ignored wheninplace=False.- inplace
bool(default:True) If
True, write each stain as a separate single-channel image under theimage_key_addedprefix and returnNone; the write is atomic (all target keys are validated free before any is written). IfFalse, leavesdatauntouched and return the maps as a dict.- output_dtype
DTypeLike(default:<class 'numpy.float16'>) Dtype of the concentration maps. Defaults to
float16(half the storage; ~3 significant figures, adequate for concentrations); passfloat32for strict quantification.- include_residual
bool(default:True) If
True, also produce the"residual"map. The residual is the absorbance along the complement direction - a diagnostic of decomposition quality (extra chromogen, artifacts, or a poor fit), not a biological stain. SetFalseto keep onlyhematoxylin/eosin.
- sdata
- Returns:
dict[str,DataArray] |None–Noneifinplace=True(the maps are written as separate images), otherwise adictmapping each stain name to its(y, x)concentrationDataArray("hematoxylin","eosin", and"residual"unless dropped).