lazyslide.pp.find_tissues

Contents

lazyslide.pp.find_tissues#

find_tissues(wsi, level='auto', refine_level=None, method='otsu', to_hsv=False, blur_ksize=17, threshold=7, morph_n_iter=3, morph_ksize=7, min_tissue_area=0.001, min_hole_area=1e-05, detect_holes=True, filter_artifacts=True, disk_radius=4, relaxed_threshold=True, invert_check=True, key_added='tissues')#

Find tissue regions in the WSI and add them as contours and holes.

Note

The results may not be deterministic between runs, as the segmentation level is automatically decided by the available memory. To get a consistent result, you can set the level parameter to a specific value. Set level=-1 for the lowest resolution level and fastest tissue segmentation speed.

See also

zs.seg.tissue

Parameters:
wsiWSIData

The WSIData object to work on.

levelint, default: ‘auto’

The level to use for segmentation.

refine_levelint or ‘auto’, default: None

The level to refine the tissue polygons.

method{‘otsu’, ‘entropy’}, default: ‘otsu’

Tissue mask construction strategy. 'otsu' uses median blur + Otsu/artifact thresholding + morphological closing. 'entropy' uses HED color-space local entropy with Otsu thresholding followed by morphological closing; when method='entropy' the otsu-specific parameters (to_hsv, blur_ksize, threshold, filter_artifacts) are ignored.

to_hsvbool, default: False

(otsu only) The tissue image will be converted from RGB to HSV space, the saturation channel (color purity) will be used for tissue detection.

blur_ksizeint, default: 17

(otsu only) The kernel size used to apply median blurring.

thresholdint, default: 7

(otsu only) The threshold for binary thresholding.

morph_n_iterint, default: 3

The number of iterations of morphological closing to apply (also applied as opening on the otsu path).

morph_ksizeint, default: 7

The kernel size for morphological closing (also applied as opening on the otsu path).

min_tissue_areafloat, default: 1e-3

The minimum area of tissue.

min_hole_areafloat, default: 1e-5

The minimum area of holes.

detect_holesbool, default: True

Detect holes in tissue regions.

filter_artifactsbool, default: True

(otsu only) Filter artifacts out. Artifacts that are non-redish are removed.

disk_radiusint, default: 4

(entropy only) Radius of the disk structuring element used for entropy filtering.

relaxed_thresholdbool, default: True

(entropy only) If True, use a more permissive threshold (0.85x Otsu) and aggregate only hematoxylin and eosin entropy. If False, also subtract DAB entropy, producing a stricter mask.

invert_checkbool, default: True

(entropy only) Whether to detect and correct mask inversion when the background dominates the image borders.

key_addedstr, default: ‘tissues’

The key to save the result in the WSIData object.

Returns:
GeoDataFrame

The tissues dataframe, with columns of tissue_id and geometry. Added to shapes.

Examples

>>> import lazyslide as zs
>>> wsi = zs.datasets.sample(with_data=False)
>>> zs.pp.find_tissues(wsi)
>>> zs.pl.tissue(wsi)
../../_images/lazyslide-pp-find_tissues-1.png