# How to get the segmentation data?

**URL:** <https://discourse.slicer.org/t/how-to-get-the-segmentation-data/34049>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [January 30, 2024, 1:39pm UTC](https://discourse.slicer.org/t/how-to-get-the-segmentation-data/34049 "2024-01-30T13:39:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tueboesen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tueboesen/32/69242_2.png) [@tueboesen](https://discourse.slicer.org/u/tueboesen)\
**Post date:** [January 30, 2024, 1:39pm UTC](https://discourse.slicer.org/t/how-to-get-the-segmentation-data/34049/1 "2024-01-30T13:39:39Z")

</div>

I am still learning my way around slicer 3D.

I have learned that I can get the data volume in numpy format as:  
data\_vol = getNode(‘Data’)  
data\_vol\_np = slicer.utils.arrayFromVolume(data\_vol)

Now I would like to be able to get the segmentations as well somehow.

I can get the segmentation node as:  
b = getNode(‘Segmentation’)

and in that I can get the actual segmentations as:  
c = b.GetSegmentation()

and under that I can get the n’th segmentation layer as:

d=c.GetNthSegment(n)

But how do I actually get a numpy dataset of the segmentations? I still haven’t found that in all this.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 30, 2024, 3:47pm UTC](https://discourse.slicer.org/t/how-to-get-the-segmentation-data/34049/2 "2024-01-30T15:47:28Z")

</div>

The script repository is always worth looking through:

[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#read-and-write-a-segment-as-a-numpy-array](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#read-and-write-a-segment-as-a-numpy-array)
