How to get the master volume of a segmentation with Python

Dear Slicer communnity,

sorry if this was already asked before. I would like to ask how can I get the master volume node from of a segmentation in the Python interactor.

Thank you very much in advance.

Samuel

EDIT: I figured out. I used the following code:

segment_editor_node = getNode('SegmentEditor')

followed by

refvol = segment_editor_node.GetMasterVolumeNode()

Is this the proper to way to do it?

It can be if in your use case you only have one segmentation, however it can get you the wrong result if you are editing another segmentation than which you want to get the master volume of.

This is the way to get the volume which gave the geometry of the segmentation: Slicer/SegmentStatisticsSubjectHierarchyPlugin.py at master · Slicer/Slicer · GitHub

1 Like