> For the complete documentation index, see [llms.txt](https://help.connected.illumina.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.connected.illumina.com/dragen-stratamap/dragen-spatial-transcriptome/analysis-inputs/external-cell-segmentation-optional.md).

# External Cell Segmentation (Optional)

DRAGEN Spatial Transcriptome analysis software supports externally generated custom cell segmentation results (either nuclei or cell segmentation masks) for cell bin matrix generation. **This input is optional.**

{% hint style="info" %}
When generating a custom segmentation mask, be sure to use the registered OME-TIFF output from the Illumina Spatial Image Tool.
{% endhint %}

To input a custom segmentation mask for analysis, make sure the segmentation files in the external\_segmentation folder are in ***TIFF*** format, and the corresponding segmentation filename contains Sample\_ID and ends with either:

'*\_nuclei\_segmentation\_mask.tif*' (nuclei segmentation mask) or

'*\_cell\_segmentation\_mask.tif*' (cell segmentation mask)

**For nuclei segmentation mask input:** DRAGEN Spatial Transcriptome analysis software will perform border expansion to create the cell segmentation mask. The default '*expansion\_um*' parameter is 5 µm, but it can be modified. Both the nuclei bin matrix and cell bin matrix will be generated.

**For custom cell segmentation mask input:** DRAGEN Spatial Transcriptome analysis software will **not** perform border expansion and will generate the cell bin matrix using the cell segmentation input. When using a cell segmentation mask, please make sure you have performed the expansion yourself.

When generating the segmentation mask TIFF files, please make sure they are instance segmentation masks, in which each nuclei/cell mask (and corresponding pixels) has its own unique object integer ID number.

If the segmentation mask is in binary format (1 for nuclei/cell mask, 0 for background), you can convert it into an instance segmentation:

1. By running a script—for example, Python functions such as '[skimage.measure.label](https://scikit-image.org/docs/0.24.x/api/skimage.measure.html#skimage.measure.label)', '[scipy.ndimage.label](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.label.html)', or '[cv2.connectedComponents](https://docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html#gaedef8c7340499ca391d459122e51bef5)'. Here is an example script for this conversion:

```
import numpy as np
import tifffile as tiff
from scipy.ndimage import label

# Example usage
if __name__ == "__main__":
    # load the binary segmentation mask file
    binary_mask = tiff.imread("Sample1_binary_nuclei_segmentation_mask.tif")
    
    # convert the binary segmentation mask into instance segmentation mask
    instance_mask, num_features = label(binary_mask)
    
    # Save labeled array as a TIFF file
    tiff.imwrite("Sample1_instance_nuclei_segmentation_mask.tif", instance_mask.astype(np.uint32))
```

2. By using image analysis software like ImageJ (Fiji): use 'Plugins' -> 'Process' -> 'Find\_Connected\_Regions' and set 'Regions for values over: ' to '0'.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.connected.illumina.com/dragen-stratamap/dragen-spatial-transcriptome/analysis-inputs/external-cell-segmentation-optional.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
