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

# Tissue segmentation

> Separate tissue from background before feature extraction.

The tissue segmentation model identifies tissue regions in a slide, letting you discard background tiles before running [H-Optimus](/documentation/models/h-optimus) or [M-Optimus](/documentation/models/m-optimus). It is bundled with both model packages.

## Specifications

| Property             | Value                                                                |
| -------------------- | -------------------------------------------------------------------- |
| Task                 | Binary tissue mask                                                   |
| Input                | 512×512 RGB tile at 8.0 µm/px                                        |
| Output               | Flattened binary mask of length 262,144 (512×512), values 0.0 or 1.0 |
| SageMaker dispatch   | `model_name: "tissue-seg"`, `mode: "prediction"`                     |
| Recommended instance | `ml.g5.xlarge`                                                       |

<Tip>
  Run segmentation at the coarse 8.0 µm/px resolution first; it is cheap relative to per-tile feature extraction at 0.5 µm/px and can dramatically reduce the number of tiles you embed.
</Tip>

## Reshaping the output

The endpoint returns a flat array. Reshape it to a 512×512 mask:

```python theme={null}
import numpy as np

mask = np.array(result["output"]).reshape(512, 512)
```

## Deploy

Tissue segmentation has no separate deployment — it is **bundled with both the H-Optimus and M-Optimus packages** and served from the same endpoint. Deploy either model (see the [Deployment overview](/deployment/overview)) and `tissue-seg` is available alongside it.

## Using it in a pipeline

In practice you rarely call this endpoint directly — the Bioptimus SDK's tissue mask provider generates and caches masks for you, then filters tiles before feature extraction or prediction. See [Spatial transcriptomics](/guides/workflows/spatial-transcriptomics) and the [Bioptimus SDK](/guides/get-started/sdk).

Once masks are generated, `bioptimus.utils.plot_slide_and_mask` renders the mask next to the slide thumbnail for a quick sanity check:

```python theme={null}
from bioptimus import utils

record = cohort[0]
utils.plot_slide_and_mask(record.wsi_path, record.mask_path, threshold=0.5)
```

<Frame caption="Tissue mask (right) beside the slide thumbnail (left) for a TCGA-LUAD slide (TCGA-75-7027). Background is discarded before feature extraction. Representative example.">
  <img src="https://mintcdn.com/bioptimus-79a2297b/wzVDcCnzT959rZil/images/figures/tissue-mask-overlay.png?fit=max&auto=format&n=wzVDcCnzT959rZil&q=85&s=87a8dc92ffd6911fc6305d1d59b3b2fa" alt="Slide thumbnail alongside its binary tissue mask" width="1028" height="480" data-path="images/figures/tissue-mask-overlay.png" />
</Frame>
