> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bioptimus.preprocess.wsi.provider.precomputed

> Pre-computed tissue mask provider.

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

```python theme={null}
class PrecomputedTissueMask(TissueMaskProvider)
```

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)`.

<ParamField body="mask_dir" type="str | Path">
  Directory containing mask files.
</ParamField>

<ParamField body="suffix" type="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.
</ParamField>

**Raises:**

* `FileNotFoundError` — At `generate` time if no matching mask file is found for a slide. **Example**

```python theme={null}
from bioptimus.preprocess.wsi.provider.precomputed import (
PrecomputedTissueMask,
)
```

# 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

```python theme={null}
def generate(reader: WSIReader, *, show_progress: bool = True) -> np.ndarray
```

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.

<ParamField body="reader" type="WSIReader" required>
  An **open** WSI reader.
</ParamField>

<ParamField body="show_progress" type="bool">
  Ignored for pre-computed masks (kept for interface compatibility).
</ParamField>

<ResponseField name="returns" type="np.ndarray">
  A `uint8` mask of shape `(H, W)` with values in `{0, 1}` where `1` = tissue / region of interest.
</ResponseField>

**Raises:**

* `FileNotFoundError` — If no mask file is found for the slide.
