How to automatically convert a labelmap volume to a segmentation node upon loading labelmap volume

Hi,

So, the script below only allows me to convert a labelmap volume that has already been added to the scene. Is there a way to modify the script so that it applies to all LabelMap volumes I load even if they have not been added to the scene?

labelmapVolumeNode = getNode(‘my_labelmap_name’)
seg = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLSegmentationNode’)
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode, seg)

1 Like