AnnotationTileGenerator¶

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

Define AnnotationTileGenerator for rendering AnnotationStore.

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.

Initialize AnnotationTileGenerator.

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.

Parameters:

self (AnnotationTileGenerator)

Return type:

Image

get_tile(level, x, y, res=1, pad_mode=None, interpolation=None, transparent_value=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) – The resolution of the tile. Defaults to 1, can be set to 2 for double resolution.

  • pad_mode (str) – Method for padding at edges of the WSI. Default to ‘constant’. See numpy.pad() for more information.

  • interpolation (str) – Method of interpolation. Possible values are: nearest, linear, cubic, lanczos, area. Defaults to nearest.

  • transparent_value (int) – Not used by AnnotationTileGenerator.

  • self (AnnotationTileGenerator)

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:
Return type:

tuple[int, int]