WSIMeta

class WSIMeta(slide_dimensions, axes, level_dimensions=None, objective_power=None, level_count=None, level_downsamples=(1,), vendor=None, mpp=None, file_path=None, raw=None)[source]

Whole slide image metadata class.

Parameters
  • slide_dimensions (int, int) – Tuple containing the width and height of the WSI. These are for the baseline (full resolution) image if the WSI is a pyramid or multi-resolution.

  • level_dimensions (list) – A list of dimensions for each level of the pyramid or for each resolution in the WSI.

  • objective_power (float, optional) – The power of the objective lens used to create the image.

  • level_count (Optional[int]) – (int, optional): The number of levels or resolutions in the WSI. If not given this is assigned len(level_dimensions). Defaults to None.

  • level_downsamples (list of float) – List of scale values which describe how many times smaller the current level is compared with the baseline.

  • vendor (str, optional) – Scanner vendor/manufacturer description.

  • mpp (float, float, optional) – Microns per pixel.

  • file_path (Path, optional) – Path to the corresponding WSI file.

  • raw (dict, optional) – Dictionary of unprocessed metadata extracted from the WSI format. For JPEG-2000 images this contains an xml object under the key “xml”.

  • axes (str) –

slide_dimensions

Tuple containing the width and height of the WSI. These are for the baseline (full resolution) image if the WSI is a pyramid or multi-resolution. Required.

Type

tuple(int)

axes

Axes ordering of the image. This is most relevant for OME-TIFF images where the axes ordering can vary. For most images this with be “YXS” i.e. the image is store in the axis order of Y coordinates first, then X coordinates, and colour channels last.

Type

str

level_dimensions

A list of dimensions for each level of the pyramid or for each resolution in the WSI. Defaults to [slide_dimension].

Type

list

objective_power

The magnification power of the objective lens used to scan the image. Not always present or accurate. Defaults to None.

Type

float

level_count

(int): The number of levels or resolutions in the WSI. If not given this is assigned len(level_dimensions). Defaults to len(level_dimensions).

level_downsamples

List of scale values which describe how many times smaller the current level is compared with the baseline. Defaults to (1,).

Type

list of float

vendor

Scanner vendor/manufacturer description.

Type

str

mpp

Microns per pixel. Derived from objective power and sensor size. Not always present or accurate. Defaults to None.

Type

float, float, optional

file_path

Path to the corresponding WSI file. Defaults to None.

Type

Path

raw

Dictionary of unprocessed metadata extracted from the WSI format. For JP2 images this contains an xml object under the key “xml”. Defaults to empty dictionary.

Type

dict

Methods

as_dict

Convert WSIMeta to dictionary of Python types.

level_downsample

Get the downsample factor for a level.

relative_level_scales

Calculate scale of each level in the WSI relative to given resolution.

validate

Validate passed values and cast to Python types.

as_dict()[source]

Convert WSIMeta to dictionary of Python types.

Returns

Whole slide image meta data as dictionary.

Return type

dict

level_downsample(level)[source]

Get the downsample factor for a level.

For non-integer values of level, the downsample factor is linearly interpolated between from the downsample factors of the level below and the level above.

Parameters

level (int or float) – Level to get downsample factor for.

Returns

Downsample factor for the given level.

Return type

float

relative_level_scales(resolution, units)[source]

Calculate scale of each level in the WSI relative to given resolution.

Find the relative scale of each image pyramid / resolution level of the WSI relative to the given resolution and units.

Values > 1 indicate that the level has a larger scale than the target and < 1 indicates that it is smaller.

Parameters
  • resolution (float or tuple(float)) – Scale to calculate relative to units.

  • units (str) – Units of the scale. Allowed values are: “mpp”, “power”, “level”, “baseline”. Baseline refers to the largest resolution in the WSI (level 0).

Raises
Returns

Scale for each level relative to the given scale and units.

Return type

list

Examples

>>> from tiatoolbox.wsicore.wsireader import WSIReader
>>> wsi = WSIReader.open(input_img="./CMU-1.ndpi")
>>> print(wsi.info.relative_level_scales(0.5, "mpp"))
[array([0.91282519, 0.91012514]), array([1.82565039, 1.82025028]) ...
>>> from tiatoolbox.wsicore.wsireader import WSIReader
>>> wsi = WSIReader.open(input_img="./CMU-1.ndpi")
>>> print(wsi.info.relative_level_scales(0.5, "baseline"))
[0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0]
validate()[source]

Validate passed values and cast to Python types.

Metadata values are often given as strings and must be parsed/cast to the appropriate python type e.g. “3.14” to 3.14 etc.

Returns

True is validation passed, False otherwise.

Return type

bool