squidpy.experimental.im.decompose_stains
- squidpy.experimental.im.decompose_stains(sdata, image_key, reference_or_method, *, scale='auto', method_params=None, white_point=None, image_key_added=None, inplace=True, output_dtype=<class 'numpy.float16'>, tissue_mask_key=None, include_residual=True)[source]
Decompose an image into separate per-stain concentration maps.
- 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.reference_or_method (
Union[StainReference,Literal['macenko','vahadane']]) – Either a decompositionStainReference(its stain matrix and white point are used) or a method name ("macenko"/"vahadane") to fit on this image first. The reference is the provenance record of how the maps were produced (method, stain matrix, white point).scale (
Union[str,Literal['auto']]) – As forfit_stain_reference()(only used when a method name is given; a reference is projected as-is and needs no tissue mask).method_params (
ReinhardParams|MacenkoParams|VahadaneParams|Mapping[str,Any] |None) – As forfit_stain_reference()(only used when a method name is given; a reference is projected as-is and needs no tissue mask).white_point (
ndarray|None) – As forfit_stain_reference()(only used when a method name is given; a reference is projected as-is and needs no tissue mask).tissue_mask_key (
str|None) – As forfit_stain_reference()(only used when a method name is given; a reference is projected as-is and needs no tissue mask).image_key_added (
str|None) – Key prefix for the written images wheninplace=True. IfNone(default),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) – IfTrue(default), 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) – Dtype of the concentration maps. Defaults tofloat16(half the storage; ~3 significant figures, adequate for concentrations); passfloat32for strict quantification.include_residual (
bool) – IfTrue(default), 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.
- Return type:
- Returns:
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).