sddb.loader.TissueMask#

class sddb.loader.TissueMask(**detect_tissue_kwargs: Any)#

Detect tissue with squidpy.experimental.im.detect_tissue() and flag the cells on it.

squidpy runs on the source image's coarsest level, the level its scale="auto" reads (_detect_tissue.py get_element_data(img_node, "auto")), which Rasterize keeps on the item in the role's dtype. That level is passed as a single-scale image: on the multiscale element squidpy would upscale the mask to scale 0 in memory (_get_target_upscale_shape, _affine_upscale_nearest), a full-resolution int32 array per slide. squidpy downscales further above auto_max_pixels itself. The mask, at that level, is kept on the item for StainNormalize and resampled (order 0, the affine Rasterize used for the image) onto the written grid as labels["tissue"] (uint8, 1 = tissue, 0 off the image). obs["in_tissue"] is the mask at each cell's centroid, so the step runs after Centroids.

The default is squidpy's "weka" method (a random forest trained on corner pixels as glass and the pixels least like them as tissue, squidpy _detect_tissue.py _segment_weka) with method_params={"rng": 0}, so that a rerun gives the same mask (squidpy's own default draws the forest from OS entropy), corner_size_pct=0.05 (corner boxes of 5% of the height and width; squidpy's 1% left a fringe of glass on the Atera brain slide) and corners_are_background="auto": a corner counts as glass when the mean grey value of its box is closer to that of the brightest corner box than to the median grey value of the level. squidpy takes only fixed corner flags (corners_are_background: one bool or four), so this rule stays here. A corner that the tissue covers is then not taken as glass (on the Atera cervical slide, squidpy's default of all four corners gave 67% tissue and left out the stroma in the top-right corner; this rule gives 81%). If no corner passes, all four are used. squidpy's default "otsu" splits pale tissue from glass poorly: on the Atera brain slide it kept only the nuclei, and its area filter then removed them all (docs/use_cases/loader_atera.md).

weka needs an image large enough for its corner boxes to hold glass: with squidpy's 1% boxes it marked a 256 x 256 synthetic image (boxes of 2 x 2 pixels) as all tissue and found the tissue at 512 x 512. The unit tests run otsu, downscaled by squidpy to 32 x 32, for that reason.

Parameters:
**detect_tissue_kwargs

Passed to detect_tissue(), except image_key, scale, inplace and new_labels_key, which this step sets. corners_are_background may also be "auto" (the default, see above). method_params defaults to {"rng": 0} only with method="weka".

Attributes table#

Methods table#

build(sdata)

Return the item with labels["tissue"] and obs["in_tissue"].

from_record(rec)

Rebuild the step from to_record()'s output.

requirements()

obsm["spatial"] from Centroids.

to_record()

The step as an AdapterRecord that from_record() rebuilds.

validate(sdata)

Require the centroids and the source's coarsest level from Rasterize.

validate_meta(meta)

No catalog metadata decides these steps; the checks run on the item in validate().

Attributes#

name: ClassVar[str] = 'TissueMask'#
version: ClassVar[str] = '0.2.0'#
config: dict[str, Any]#

Methods#

build(sdata: LoaderItem) → LoaderItem#

Return the item with labels["tissue"] and obs["in_tissue"].

classmethod from_record(rec: AdapterRecord) → Self#

Rebuild the step from to_record()'s output.

Raises:

ValueError -- If the record is of another adapter or another version.

requirements() → dict[str, Any]#

obsm["spatial"] from Centroids.

to_record() → AdapterRecord#

The step as an AdapterRecord that from_record() rebuilds.

validate(sdata: LoaderItem) → list[str]#

Require the centroids and the source's coarsest level from Rasterize.

validate_meta(meta: ObjectMeta) → list[str]#

No catalog metadata decides these steps; the checks run on the item in validate().