wsidata.TileSpec#

class TileSpec(height, width, stride_height, stride_width, mpp=None, ops_level=0, ops_downsample=1, base_level=0, base_downsample=1.0, tissue_name=None)#

Bases: object

Data class for storing tile specifications.

Note

Tile coordinates (x, y) from shape bounds are always in level 0 coordinates.

To enable efficient tils generation, there are 3 levels of tile size:

  1. The destined tile size and level requested by the user

  2. The tile size and level used by the image reader to optimize the performance

  3. The actual tile size at the level 0

This enables user to request tile size and level that are not exist in the image pyramids. For example, if our slide is mpp=0.5 (20X) with pyramids of mpp=[0.5, 2.0, 4.0], and user request mpp=1.0 (10X) with tile size 512x512. There is no direct level to read from, we need to read from mpp=0.5 with tile size of 1024x1024 and downsample to 512x512.

Parameters:
heightint

The height of the tile.

widthint

The width of the tile.

stride_heightint

The height of the stride.

stride_widthint

The width of the stride.

mppfloat, default: None

The requested microns per pixel of tiles.

ops_levelint, default: 0

The level of the tiling operation.

ops_downsamplefloat, default: 1

The downsample factor to transform the operation level tiles to the requested level.

tissue_namestr, optional

The name of the tissue.

Attributes:
ops_{height, width}int

The height/width of the tile when retrieving images.

ops_stride_{height, width}: int

The height/width of the stride when retrieving images.

base_{height, width}int

The height/width of the tile at the level 0.

base_stride_{height, width}int

The height/width of the stride at the level 0.

property base_height#

The height of the tile at the level 0.

property base_stride_height#

The height of the stride at the level 0.

property base_stride_width#

The width of the stride at the level 0.

property base_width#

The width of the tile at the level 0.

classmethod from_wsidata(wsi, tile_px, stride_px=None, overlap=None, mpp=None, ops_level=None, slide_mpp=None, tissue_name=None)#

Create a TileSpec from a WSIData object.

To tile from the whole slide image, the user needs to specify the tile size and stride size. mpp only need to be specified if the user wants to make sure the tile size is harmonized across different slides.

If ops_level is not specified, the optimal level will be calculated based on the requested mpp to maximize the performance.

Parameters:
wsiWSIData

The whole-slide image data object.

tile_pxint or (int, int)

Tile size in pixels. If a tuple, interpreted as (width, height).

stride_pxint or (int, int), optional

Stride size in pixels. If a tuple, interpreted as (width, height).

overlapfloat or (float, float), optional

Overlap fraction or pixel count. Cannot be specified together with stride_px.

mppfloat, optional

Requested microns per pixel.

ops_levelint, optional

Override the pyramid level used for reading.

slide_mppfloat, optional

Override the slide’s recorded mpp.

tissue_namestr, optional

Name of the tissue to tile.

property is_overlap#

Check if the tiles are overlapped.

property is_overlap_x#

Check if the tiles are overlapped along the x-axis.

property is_overlap_y#

Check if the tiles are overlapped along the y-axis.

property ops_height#

The height of the tile when retrieving images.

property ops_stride_height#

The height of the stride when retrieving images.

property ops_stride_width#

The width of the stride when retrieving images.

property ops_width#

The width of the tile when retrieving images.

property overlap_x#

The overlap pixel size along the x-axis.

property overlap_y#

The overlap pixel size along the y-axis.

to_dict()#

Convert the TileSpec to a dictionary.

to_json()#

Convert the TileSpec to a JSON string.