SlidingWindowPatchExtractor

class SlidingWindowPatchExtractor(input_img, patch_size, input_mask=None, resolution=0, units='level', stride=None, pad_mode='constant', pad_constant_values=0, min_mask_ratio=0, store_filter=None, *, within_bound=False)[source]

Extract patches using sliding fixed sized window for images and labels.

Parameters:
  • input_img (str, pathlib.Path, numpy.ndarray, WSIReader) – Input image for patch extraction.

  • patch_size (int or tuple(int)) – Patch size tuple (width, height).

  • input_mask (str | Path | np.ndarray | wsireader.VirtualWSIReader | None) – (str, pathlib.Path, numpy.ndarray, or VirtualWSIReader): Input mask that is used for position filtering when extracting patches i.e., patches will only be extracted based on the highlighted regions in the input_mask. input_mask can be either path to the mask, a numpy array, VirtualWSIReader, or one of ‘otsu’ and ‘morphological’ options. In case of ‘otsu’ or ‘morphological’, a tissue mask is generated for the input_image using tiatoolbox TissueMasker functionality.

  • resolution (Resolution) – Resolution at which to read the image, default = 0. Either a single number or a sequence of two numbers for x and y are valid. This value is in terms of the corresponding units. For example: resolution=0.5 and units=”mpp” will read the slide at 0.5 microns per-pixel, and resolution=3, units=”level” will read at level at pyramid level / resolution layer 3.

  • units (Units) – The units of resolution, default = “level”.

  • pad_mode (str) – Method for padding at edges of the WSI. Default to ‘constant’. See numpy.pad() for more information.

  • pad_constant_values (int or tuple(int)) – Values to use with constant padding. Defaults to 0. See numpy.pad() for more information.

  • within_bound (bool) – Whether to extract patches beyond the input_image size limits. If False, extracted patches at margins will be padded appropriately based on pad_constant_values and pad_mode. If True, patches at the margins whose bounds would exceed the mother image dimensions would be neglected. Default is False.

  • stride (int or tuple(int)) – Stride in (x, y) direction for patch extraction, default = patch_size.

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

  • store_filter (str) – Filter to apply to the annotations when generating the mask. Default is None, which uses all annotations. Only used if the provided mask is an annotation store.

stride

Stride in (x, y) direction for patch extraction.

Type:

tuple(int)

Initialize SlidingWindowPatchExtractor.

Methods