lazyslide_models.tile_prediction.cv_features.ColorDeconvolution

lazyslide_models.tile_prediction.cv_features.ColorDeconvolution#

class ColorDeconvolution(stain='hed')#

Bases: _CVFeatures

color_deconvolution Paper [Ruifrok and Johnston, 2001] Mean amount of each stain in a tile (hematoxylin, eosin, DAB), by color deconvolution

Measure the stains in a tile by color deconvolution.

Each pixel’s optical density is unmixed into the amounts of three stains, given their RGB absorption vectors, and each amount is averaged over the tile. On an IHC slide, dab measures the chromogen.

The amounts are in the units of skimage.color.separate_stains, so the default equals skimage.color.rgb2hed averaged over the tile: a pixel holding amounts s of stains with RGB vectors V transmits 10 ** (-6 * s @ V) of the light. Negative amounts are clipped to zero in each pixel.

An absent stain does not read zero, since real pixels are never exact mixtures of the stain vectors: an H&E slide reads a dab of about 0.02 to 0.05, so compare tiles with each other or with a negative control. White background adds zero, so a tile with less tissue has a lower mean; for statistics over the tissue alone, use ColorDeconvolutionMap. The presets are published stain vectors. Stain colors vary with the staining batch and the scanner, so pass measured vectors when the numbers matter.

>>> zs.tl.tile_prediction(wsi, "color_deconvolution")
>>> tiles = wsi["tiles"]
>>> tiles[tiles["dab"] > tiles["dab"].quantile(0.9)]
Parameters:
stainstr or dict, default: “hed”

The stains to unmix. "hed" gives hematoxylin, eosin and dab; "hdx" gives hematoxylin, dab and a residual, for IHC without eosin. A dict of exactly three {name: vector} entries unmixes custom stains: each vector is the stain’s optical density in red, green and blue, like a row of skimage.color.rgb_from_hed. The names become the columns.

columns = ('hematoxylin', 'eosin', 'dab')#

Subclasses whose _func returns a dict set this explicitly; for the rest it is derived below from the class name, which is the same rule _process_batch uses to key its result.