lazyslide.seg.tissue

Contents

lazyslide.seg.tissue#

tissue(wsi, *, model='pathprofiler', level=None, mpp=None, bbox_ratio=0.05, min_area=0.001, min_hole_area=1e-05, detect_holes=True, threshold=0.5, tile_px=1024, device=None, amp=None, autocast_dtype=None, compile=None, compile_kws=None, key_added='tissues')#

Perform tissue segmentation powered by a deep learning model.

Models with a built-in input resolution:

Any other segmentation model runs at the mpp or level you pass.

The model runs on overlapping tiles at the working mpp (see tile_px), blended with a Gaussian window, so its memory use does not grow with the slide: HEST at 1 µm/px on a 20k px slide is a ~10k px image, far too big for one forward pass. An image that fits in one tile goes through in a single pass.

Parameters:
wsiWSIData

The whole slide image.

modelstr or SegmentationModelProtocol, default: “pathprofiler”

The model to use for tissue segmentation: a model registry key (see Models) or a model instance.

levelint, default: None

The level to segment the tissue, mutually exclusive with mpp.

mppfloat, default: None

The mpp level to segment the tissue, mutually exclusive with level.

bbox_ratiofloat, default: 0.05

The ratio of the bounding box to filter the false positive tissue polygons.

min_areafloat, default: 1e-3

The minimum area of the tissue polygon.

min_hole_areafloat, default: 1e-5

The minimum area of the hole in the tissue polygon.

detect_holesbool, default: True

Whether to detect holes in the tissue polygons.

thresholdfloat, default: 0.5

The probability threshold to consider a pixel as tissue.

tile_pxint, default: 1024

The tile size in px at the working mpp, rounded down to a size the model accepts. Smaller tiles save memory; bigger ones give the model more context.

devicestr, default: None

The device to run the model.

ampbool, optional

Whether to use automatic mixed precision.

autocast_dtypetorch.dtype, optional

The dtype for automatic mixed precision.

compilebool, optional

Whether to compile the model with torch.compile(). Compilation is best-effort and is silently skipped for models that do not support it.

compile_kwsdict, optional

Keyword arguments passed to torch.compile().

key_addedstr, default: ‘tissues’

The key to add the tissue polygons.

Returns:
None

The tissue polygons are added to the shapes slot of the WSIData object.