> 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/outputs/results-folder/cell-and-nuclei-contours-csvs.md).

# Cell and Nuclei Contours CSVs

Cell and Nuclei Contours CSV files contain the approximated contour coordinates of each individual cell or nucleus detected through tissue image segmentation analysis. Each Contours CSV file has three columns:

* **cell\_id**: A unique identifier for each individual cell or nucleus within the segmentation mask.
* **vertex\_x**: The global x-coordinate of a contour point corresponding to the cell\_id (unit: µm).
* **vertex\_y**: The global y-coordinate of a contour point corresponding to the cell\_id (unit: µm).

An example of a Contours CSV file:

```
cell_id,vertex_x,vertex_y
1,36296.0,3863.2
1,36291.8,3862.0
1,36291.8,3857.0
1,36294.0,3854.8
1,36299.2,3857.0
1,36299.2,3861.0
1,36296.0,3863.2
2,36523.0,3730.2
2,36520.0,3730.2
2,36516.8,3728.0
2,36515.8,3723.0
2,36517.0,3721.8
2,36521.0,3721.8
2,36523.2,3724.0
2,36524.2,3728.0
2,36523.0,3730.2
3,36367.0,3869.2
3,36364.0,3869.2
3,36362.8,3868.0
```

### View Contour File over Microscope Image

The following Python code demonstrates how to load the registered image from the OME-TIFF file and the corresponding CSV file containing nuclei or cell contour coordinates, then overlay these contours on the tissue image for visualization.

```
from tifffile import TiffFile
from ome_types import from_tiff
import matplotlib.pyplot as plt
import pandas as pd
import json
 
# Load the registered image at 1 µm/pixel resolution from the OME-TIFF file
ome_tiff_file_path='/path/to/the/registered/ome.tiff'
with TiffFile(ome_tiff_file_path) as tif:
    image_1um = tif.pages[2].asarray()
 
# Extract global positional shift (top-left offset) from OME-TIFF metadata
ome = from_tiff(ome_tiff_file_path)
ome_obj = json.loads(ome.json())
global_top = float(ome_obj['structured_annotations']['map_annotations'][0]['value']['GlobalPos_top'])
global_left = float(ome_obj['structured_annotations']['map_annotations'][0]['value']['GlobalPos_left'])
 
# Load nuclei contour coordinates from CSV
nuclei_contour_file='/path/to/the/example_nuclei_contour_coords.csv'
contour_data = pd.read_csv(nuclei_contour_file)
 
# Convert global contour coordinates to local image coordinates by subtracting global offset
contour_data['vertex_x_local'] = contour_data['vertex_x']-global_left
contour_data['vertex_y_local'] = contour_data['vertex_y']-global_top
 
# Group contour coordinates by cell_id for plotting individual nuclei
grouped_contour = contour_data.groupby(contour_data.cell_id)
 
# Visualize the registered image with overlaid nuclei contours
plt.figure(figsize=(10,10))
plt.imshow(image_1um)
 
c='g' # set contour color to green
for cell_id, contours in grouped_contour:
    plt.plot(contours['vertex_x_local'],contours['vertex_y_local'],f'{c}--',linewidth=1, alpha=0.6)
 
plt.title("Registered Image with Nuclei/Cell Contours")
plt.axis('off')
plt.show()
```


---

# 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/outputs/results-folder/cell-and-nuclei-contours-csvs.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.
