Overlapping Segmentions Export to NIFTI

Great idea, working perfectly now. Thanks so much for your extensive help. In case anyone else wants to do something similar, here is my final code:

# ***** THE FINAL SCRIPT *****

# Required to have 3 segments - "Mask", "Single", "Multi"

# Save Image data as Image Data.nii.gz

node = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLScalarVolumeNode')
file_path = "/Users/pete/OneDrive/ImageData.nii.gz"
properties = {'useCompression': 1}; #use compression
slicer.util.saveNode(node, file_path, properties)

# Get segmentation called "Segmentation" and rename to "Single"

segmentationNode = getNode('Segmentation')
segmentationNode.GetName()
segmentationNode.SetName('Single')

# get segment "Single" and export to Single.nii.gz

extension = "nii.gz"
useCompression = "true"
destinationFolder = "/Users/pete/OneDrive"
segmentationNode = getNode('Single')
segmentNames = ["Single"]
segmentIds = vtk.vtkStringArray()
for segmentName in segmentNames:
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
    segmentIds.InsertNextValue(segmentId)
    slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsBinaryLabelmapRepresentationToFiles(destinationFolder, segmentationNode, segmentIds, extension, useCompression)

# Get segmentation called "Single" and rename to "Multi"

segmentationNode = getNode('Single')
segmentationNode.GetName()
segmentationNode.SetName('Multi')

# get segment "Multi" and export to Multi.nii.gz

segmentationNode = getNode('Multi')
segmentNames = ["Multi"]
segmentIds = vtk.vtkStringArray()
for segmentName in segmentNames:
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
    segmentIds.InsertNextValue(segmentId)
    slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsBinaryLabelmapRepresentationToFiles(destinationFolder, segmentationNode, segmentIds, extension, useCompression)

# Get segmentation called "Multi" and rename to "Mask"

segmentationNode = getNode('Multi')
segmentationNode.GetName()
segmentationNode.SetName('Mask')

# get segment "Mask" and export to Mask.nii.gz

segmentationNode = getNode('Mask')
segmentNames = ["Mask"]
segmentIds = vtk.vtkStringArray()
for segmentName in segmentNames:
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segmentName)
    segmentIds.InsertNextValue(segmentId)
    slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsBinaryLabelmapRepresentationToFiles(destinationFolder, segmentationNode, segmentIds, extension, useCompression)

# Get segmentation called "Mask" and rename to "Segmentation"

segmentationNode = getNode('Mask')
segmentationNode.GetName()
segmentationNode.SetName('Segmentation')
segmentationNode.GetName()
2 Likes