WSIPatchDataset

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

Defines a WSI-level patch dataset.

reader

an 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].

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

check (WSIReader) for details.

units

check (WSIReader) for details.

preproc_func

Preprocessing function used to transform the input data. If supplied, then torch.Compose will be used on the input preprocs. preprocs is a list of torchvision transforms for preprocessing the image. The transforms will be applied in the order that they are given in the list. For more information, visit the following link: https://pytorch.org/vision/stable/transforms.html.

Create a WSI-level patch dataset. :param mode: can be either wsi or tile to denote the image to read is

either a whole-slide image or a large image tile.

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

  • mask_path (str or pathlib.Path) – valid mask image.

  • patch_input_shape – 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 – 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 – check (WSIReader) for details. When mode=’tile’, value is fixed to be resolution=1.0 and units=’baseline’ units: check (WSIReader) for details.

  • preproc_func – Preprocessing function used to transform the input data.

Examples

>>> # an 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