AnnotationTileGenerator#

class AnnotationTileGenerator(info, store, renderer=None, tile_size=256, downsample=2, overlap=0)[source]#

Tile generator using an AnnotationRenderer to render tiles showing annotations held in an AnnotationStore

Parameters:
  • info (WSIMeta) – An WSIMeta Object storing the metadata of the slide this generator is rendering tiles for

  • Store (AnnotationStore) – An AnnotationStore Object containing annotations to be rendered for given slide

  • renderer (AnnotationRenderer) – An AnnotationRenderer Object which will render annotations belonging to a tile according to specified parameters

  • tile_size (int) – The size of tiles to generate. Default is 256. Note that the output tile size will be \(\text{tile size} + 2 \times\text{overlap}\).

  • downsample (int) – The downsample factor between levels. Default is 2.

  • overlap (int) – The number of extra pixel to add to each edge of the tile. Default is 0.

  • store (AnnotationStore) –

Methods

get_thumb_tile

Return a thumbnail which fits the whole slide in one tile.

get_tile

Render a tile at a given level and coordinate.

level_dimensions

The total pixel dimensions of the tile pyramid at a given level.

Attributes

level_count

Number of levels in the tile pyramid.

get_thumb_tile()[source]#

Return a thumbnail which fits the whole slide in one tile.

The thumbnail output size has the longest edge equal to the tile size. The other edge preserves the original aspect ratio.

Return type:

<module ‘PIL.Image’ from ‘/home/docs/checkouts/readthedocs.org/user_builds/tia-toolbox/envs/v1.4.0/lib/python3.10/site-packages/PIL/Image.py’>

get_tile(level, x, y, res=1, pad_mode=None, interpolation=None)[source]#

Render a tile at a given level and coordinate.

Note that levels are in the reverse order of those in WSIReader. I.E. level 0 here corresponds to the lowest resolution whereas level 0 in WSIReader corresponds to the maximum resolution (baseline).

Parameters:
  • level (int) – The pyramid level of the tile starting from 0 (the whole slide in one tile, 0-0-0).

  • x (int) – The tile index in the x direction.

  • y (int) – The tile index in the y direction.

  • res (int) –

  • pad_mode (Optional[str]) –

  • interpolation (Optional[str]) –

Returns:

Pillow image of the tile.

Return type:

PIL.Image

Example

>>> from tiatoolbox.tools.pyramid import AnnotationTileGenerator
>>> from tiatoolbox.wsicore.wsireader import WSIReader
>>> from tiatoolbox.annotation.storage import SQLiteStore
>>> wsi = WSIReader.open("sample.svs")
>>> SQ=SQLiteStore.from_geojson(geo_path)
>>> tile_generator = AnnotationTileGenerator(
...   info=wsi.info,
...   store=SQ,
... )
>>> tile_0_0_0 = tile_generator.get_tile(level=0, x=0, y=0)
property level_count: int#

Number of levels in the tile pyramid.

The number of levels is such that level_count - 1 is a 1:1 of the slide baseline resolution (level 0 of the WSI).

level_dimensions(level)[source]#

The total pixel dimensions of the tile pyramid at a given level.

Parameters:

level (int) – The level to calculate the dimensions for.

Return type:

Tuple[int, int]