lazyslide.pp.tile_tissues

Contents

lazyslide.pp.tile_tissues#

tile_tissues(wsi, tile_px, *, stride_px=None, overlap=None, edge=False, mpp=None, slide_mpp=None, ops_level=None, background_filter=True, background_fraction=0.3, tissue_key='tissues', key_added='tiles', return_tiles=False)#

Generate tiles within the tissue contours in the WSI.

If there is no tissue contours, the tiles will generate for the whole image.

Parameters:
wsiWSIData

The WSIData object to work on.

tile_pxint, (int, int)

The size of the tile, if tuple, (W, H).

stride_pxint, (int, int), default: None

The stride of the tile, if tuple, (W, H). If None, use the tile size.

overlapfloat, default: None

The overlap of the tiles, exclusive with stride_px. If in (0, 1), it’s the overlap ratio. If > 1, it’s the overlap in pixels.

edgebool, default: False

Whether to include the edge tiles.

mppfloat, default: None

The requested mpp of the tiles, if None, use the slide mpp.

slide_mppfloat, default: None

This value will override the slide mpp.

ops_levelint, default: None

Which level to use for the actual tile image retrival.

background_filterbool, default: True

Whether to filter the tiles based on the background fraction.

background_fractionfloat, default: 0.3

Only used if background_filter is True. The fraction of background in the tile, if more than this, discard the tile.

tissue_keystr, default ‘tissue’

The key of the tissue contours.

key_addedstr, default ‘tiles’

The key of the tiles. If set to None, the tiles will not be added to the WSIData object.

return_tilesbool, default: False

Return the tiles dataframe.

Returns:
geopandas.GeoDataFrame

The tiles dataframe with columns tissue_id, tile_id, and geometry. Added to shapes.

TileSpec

The tile specification used to create the tiles. Added to attrs with key tile_spec.

Examples

>>> import lazyslide as zs
>>> wsi = zs.datasets.sample()
>>> zs.pp.find_tissues(wsi)
>>> zs.pp.tile_tissues(wsi, 256, mpp=0.5)
>>> zs.pl.tiles(wsi, linewidth=0.5)
../../_images/lazyslide-pp-tile_tissues-1.png