# How to add segmentation to a specific frame in sequence browser

**URL:** https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201
**Category:** Development
**Tags:** segmentation, dicom, python
**Created:** [September 4, 2024, 12:03pm UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201 "2024-09-04T12:03:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![maniron](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@maniron](https://discourse.slicer.org/u/maniron)
#### Post date: [September 4, 2024, 11:06am UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201/1 "2024-09-04T11:06:05Z")

</div>

Kindly help me out with adding my model segmentation output to a sequence browser to a specific frame . I have been trying to find a solution for along if any one have a solution let me know

---

<div class="post-metadata">

### Author: ![maniron](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@maniron](https://discourse.slicer.org/u/maniron)
#### Post date: [September 4, 2024, 12:03pm UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201/2 "2024-09-04T12:03:56Z")

</div>

Kindly help me out with adding my model segmentation output to a sequence browser to a specific frame . I have been trying to find a solution for along if any one have a solution let me know

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 12, 2024, 3:33am UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201/3 "2024-09-12T03:33:53Z")

</div>

See a complete example how you can segment each frame of a volume sequence and store the segmentation result in a segmentation sequence in [TotalSegmentator](https://github.com/lassoan/SlicerTotalSegmentator/blob/main/TotalSegmentator/TotalSegmentator.py).

---

<div class="post-metadata">

### Author: ![maniron](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@maniron](https://discourse.slicer.org/u/maniron)
#### Post date: [September 17, 2024, 6:29am UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201/4 "2024-09-17T06:29:39Z")

</div>

Thanks for responding @lassoan , can you please guide me where exactly i can find, and wanted to know how can we save sequence browser segmentation, As I tested it is saving only one frame mask for DICOM 2D + time, but in NRRD type file I could see it was saving mask for the whole volume

And I want to know how can I get segmentation details for a specific frame in sequence browser (DICOM 2D + time)

> segmentationSequenceNode = slicer.util.getNode(‘Sequence\_1’)  
> segmentationNodeForFrame = segmentationSequenceNode.GetNthDataNode(refIndex)  
> segmentation = segmentationNodeForFrame.GetSegmentation()  
> segVal = segmentation.GetNumberOfSegments()  
> segmentId = “Segment\_” + str(segVal)  
> segmentId = segmentationNodeForFrame.GetSegmentation().GetSegmentIdBySegmentName(segmentId)  
> # Get segment as numpy array  
> segVal = slicer.util.arrayFromSegmentInternalBinaryLabelmap(segmentationNodeForFrame, segmentId)

This was the code I used to get segmentation for a specific frame in sequence browser, Is this correct way

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 17, 2024, 1:54pm UTC](https://discourse.slicer.org/t/how-to-add-segmentation-to-a-specific-frame-in-sequence-browser/38201/5 "2024-09-17T13:54:43Z")

</div>

You need to implement DICOM export of time sequences yourself. It should not be complicated, you just need to export each time point with the appropriate timestamp, with the same series instance UID.

You can look up any DICOM metadata from the `DICOM.instanceUIDs` attribute of the volume. See the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#access-tag-of-a-scalar-volume-loaded-from-dicom) for a complete example.
