I want to script Slicer to automatically convert labelmap volume to a segmentation node when I load the labelmap volume, rather than having to right-click and convert it through the GUI. How can I achieve this? Can this be done in .slicerrc.py?
If you use a recent Slicer Preview version then you can load nrrd and nifti files directly as segmentation (just choose Segmentation in the Description column in Add Data dialog). If you make the segmentation filename end with .seg.nrrd then Segmentation is selected automatically.
Thanks for the reply - Yes I have copied and pasted that script into .slicerrc.py. Although when I load a volume as a LabelMap, it does not automatically get converted to a segmentation node. I am a novice user - is there something I need to specify in the script?
That is a kind offer! But I do not use python. I am hoping for a solution that can be directly applied to the slicerrc.py.
To give more context, I am loading pairs of volumes: one Scalar and one LabelMap volume - all one after the other. It is tedious to have to right click and convert the LabelMap volume to a segmentation node to perform edits. Is there a way that I can script slicerrc.py to automatically convert all LabelMap volume data to a segmentation node?
It sounds like you need CaseIterator extension, which is developed for iterating through a set of volumes and labelmaps. We use this for AI segmentation for generating training data and quality check and recently got grant funding to improve it further, based on what users need. So, if you have any feedback or suggestion then let us know.
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)