How to convert a vtkMRMLScalarVolumeNode to a vtkMRMLSegmentationNode

Hi all,
I’m trying to convert a vtkMRMLScalarVolumeNode to a new vtkMRMLSegmentationNode (in Python) and I don’t seem to get it figured out… The scalar volume is basically just a binary image but I want it to be rendered as a segmentation (contour) and not a volume.
Does anyone know how I can achieve this? Thanks in advance!

You can programmatically use the segment editor tools to generate a segment from your binary image using a threshold (check out the segmentations section of the script repository), though there is probably a simpler way given that you basically already have a thresholded image. If it helps, it looks like you can load your volume as a segmentation (see instructions here Segmentations — 3D Slicer documentation). That’s not exactly the same as converting an already loaded volume, but maybe it will work for you.

1 Like

There are convenience tools to do this conversion. Thresholding as suggested above is an error-prone workaround, so I suggest using the built-in function called ImportLabelmapToSegmentationNode, see Slicer: vtkSlicerSegmentationsModuleLogic Class Reference

2 Likes

Thank you, it was indeed the preferred method! :grinning_face_with_smiling_eyes:

I may have missed something, I see that the input to the function is a label map, is there anyway to input a volume Node instead i.e. convert the volume node to a segmentation then labelmap.

When you say “convert the volume node to a segmentation” do you mean segmenting an anatomical image like a CT or MRI? For that you need to use the Segment Editor module.

I have a binary 3D mask of a structure that I load as a volume node instead of a segmentation node, I then just want to convert it to a segmentation node later on in a post-processing step.

If your scalar volume is already a binary labelmap (just imported as a scalar volume instead), then the easiest method is to convert your scalar volume to a labelmap using the Volumes module, in the “Volume Information” section:

image

and then import the labelmap as a segmentation using the “Segmentations” module in the “Export/Import models and labelmaps” section:

image

or programmatically using ImportLabelmapToSegmentationNode as suggested above.