How to get the segmentation data?

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.

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

1 Like