> ## 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](https://docs.bioptimus.com/documentation/models/h-optimus.md) or [M-Optimus](https://docs.bioptimus.com/documentation/models/m-optimus.md). It is bundled with both model packages.

## Specifications

| Property | Value |
| - | - |
| Task | Binary tissue mask |
| Input | 512×512 RGB tile at 8.0 µm/pixel |
| 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/pixel resolution first; it is cheap relative to per-tile feature extraction at 0.5 µm/pixel and can dramatically reduce the number of tiles you embed.

## 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](https://docs.bioptimus.com/deployment/overview.md)) 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](https://docs.bioptimus.com/guides/workflows/spatial-transcriptomics.md) and the [Bioptimus SDK](https://docs.bioptimus.com/guides/get-started/sdk.md).

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

![Slide thumbnail alongside its binary tissue mask](https://mintcdn.com/bioptimus-79a2297b/wzVDcCnzT959rZil/images/figures/tissue-mask-overlay.png?fit=max\&auto=format\&n=wzVDcCnzT959rZil\&q=85\&s=87a8dc92ffd6911fc6305d1d59b3b2fa)

Tissue mask (right) beside the slide thumbnail (left) for a TCGA-LUAD slide (TCGA-75-7027). Background is discarded before feature extraction. Representative example.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.