WSIPatchDataset¶

class WSIPatchDataset(img_path, mode='wsi', mask_path=None, patch_input_shape=None, stride_shape=None, resolution=None, units=None, min_mask_ratio=0, preproc_func=None, *, auto_get_mask=True)[source]¶

Define a WSI-level patch dataset.

reader¶

A WSI Reader or Virtual Reader for reading pyramidal image or large tile in pyramidal way.

Type:

WSIReader

inputs¶

List of coordinates to read from the reader, each coordinate is of the form [start_x, start_y, end_x, end_y].

Type:

list[str | pathlib.Path | numpy.ndarray] | numpy.ndarray

patch_input_shape¶

A tuple (int, int) or ndarray of shape (2,). Expected size to read from reader at requested resolution and units. Expected to be (height, width).

resolution¶

See (WSIReader) for details.

units¶

See (WSIReader) for details.

preproc_func¶

Preprocessing function used to transform the input data. It will be called on each patch before returning it.

Create a WSI-level patch dataset.

Parameters:
  • mode (str) – Can be either wsi or tile to denote the image to read is either a whole-slide image or a large image tile.

  • img_path (str or Path) – Valid to pyramidal whole-slide image or large tile to read.

  • mask_path (str or Path) – Valid mask image.

  • patch_input_shape (IntPair) – A tuple (int, int) or ndarray of shape (2,). Expected shape to read from reader at requested resolution and units. Expected to be positive and of (height, width). Note, this is not at resolution coordinate space.

  • stride_shape (IntPair) – A tuple (int, int) or ndarray of shape (2,). Expected stride shape to read at requested resolution and units. Expected to be positive and of (height, width). Note, this is not at level 0.

  • resolution (Resolution) – Check (WSIReader) for details. When mode=’tile’, value is fixed to be resolution=1.0 and units=’baseline’ units: check (WSIReader) for details.

  • units (Units) – Units in which resolution is defined.

  • auto_get_mask (bool) – If True, then automatically get simple threshold mask using WSIReader.tissue_mask() function.

  • min_mask_ratio (float) – Only patches with positive area percentage above this value are included. Defaults to 0.

  • preproc_func (Callable) – Preprocessing function used to transform the input data. If supplied, the function will be called on each patch before returning it.

Examples

>>> # A user defined preproc func and expected behavior
>>> preproc_func = lambda img: img/2  # reduce intensity by half
>>> transformed_img = preproc_func(img)
>>> # Create a dataset to get patches from WSI with above
>>> # preprocessing function
>>> ds = WSIPatchDataset(
...     img_path='/A/B/C/wsi.svs',
...     mode="wsi",
...     patch_input_shape=[512, 512],
...     stride_shape=[256, 256],
...     auto_get_mask=False,
...     preproc_func=preproc_func
... )

Methods

Attributes

inputs

labels