Skip to main content
Pre-computed tissue mask provider. Loads a pre-existing mask from a directory on disk, matched by slide name. Useful for clinician annotations or masks produced by an external pipeline.

PrecomputedTissueMask

Loads a pre-existing mask from a directory, matched by slide name. Clinicians or annotation pipelines often produce per-slide masks (e.g. tissue regions, tumour annotations) and store them alongside the slides. This provider looks up the mask file whose stem matches the slide name and loads it. Supported formats: PNG, JPEG, TIFF, BMP (loaded via OpenCV) and .npy (loaded via load). The loaded mask is binarised (non-zero → 1) and returned as uint8 (H, W).
str | Path
Directory containing mask files.
str | None
Expected file extension including the dot (e.g. ".png"). When None (default), the provider searches for the first file in mask_dir whose stem matches the slide name, trying all supported extensions.
Raises:
  • FileNotFoundError — At generate time if no matching mask file is found for a slide. Example

Directory layout:

/data/masks/slide_001.png

/data/masks/slide_002.png

provider = PrecomputedTissueMask(mask_dir=“/data/masks/”) mask = provider.generate(reader) # reader.path → …/slide_001.svs

With explicit suffix:

provider = PrecomputedTissueMask( mask_dir=“/data/masks/”, suffix=“.tiff” )

generate

Loads the pre-computed mask that matches the slide name. Extracts the slide stem from reader.path, finds the corresponding file in mask_dir, loads and binarises it.
WSIReader
required
An open WSI reader.
bool
Ignored for pre-computed masks (kept for interface compatibility).
np.ndarray
A uint8 mask of shape (H, W) with values in {0, 1} where 1 = tissue / region of interest.
Raises:
  • FileNotFoundError — If no mask file is found for the slide.