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
Return a thumbnail which fits the whole slide in one tile.
Render a tile at a given level and coordinate.
The total pixel dimensions of the tile pyramid at a given level.
Render annotations within given bounds on top on an image.
Render annotation appropriately to its geometry type.
Attributes
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.3.0/lib/python3.10/site-packages/PIL/Image.py’>
- get_tile(level, x, y, 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:
- 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).
- render_annotations(tile, bound_geom, scale)[source]#
Render annotations within given bounds on top on an image.
This gets annotations as bounding boxes or geometries according to zoom level, and renders them. Large collections of small annotation geometries are decimated if appropriate.
- Parameters:
- Returns:
The tile with the annotations rendered.
- Return type:
np.ndarray
- render_by_type(tile, annotation, top_left, scale, poly_as_box=False)[source]#
Render annotation appropriately to its geometry type.
- Parameters:
tile (np.ndarray) – The rgb(a) tile image to render the annotation on.
annotation (Annotation) – The annotation to render.
top_left (Tuple[int, int]) – The top left coordinate of the tile.
scale (int) – The scale at which we are rendering the tile.
poly_as_box (bool) – Whether to render polygons as boxes.