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.pyget_element_data(img_node, "auto")), whichRasterizekeeps 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 aboveauto_max_pixelsitself. The mask, at that level, is kept on the item forStainNormalizeand resampled (order 0, the affineRasterizeused for the image) onto the written grid aslabels["tissue"](uint8, 1 = tissue, 0 off the image).obs["in_tissue"]is the mask at each cell's centroid, so the step runs afterCentroids.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) withmethod_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) andcorners_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(), exceptimage_key,scale,inplaceandnew_labels_key, which this step sets.corners_are_backgroundmay also be"auto"(the default, see above).method_paramsdefaults to{"rng": 0}only withmethod="weka".
Attributes table#
Methods table#
build(sdata)Return the item with
labels["tissue"]andobs["in_tissue"].from_record(rec)Rebuild the step from
to_record()'s output.obsm["spatial"]fromCentroids.The step as an
AdapterRecordthatfrom_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#
Methods#
- build(sdata: LoaderItem) LoaderItem#
Return the item with
labels["tissue"]andobs["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.
- to_record() AdapterRecord#
The step as an
AdapterRecordthatfrom_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().