I have loaded a patient volume, its segmentation, and the corresponding RTSTURCT.
I need to save the components of the RTSTRUCT as separate nifti files using the python command line, but I have no idea how I can do that.
I figured it out.
First, a for loop was needed over the visible segment ids.
Then the following two commands to export the segments:
slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsToLabelmapNode(segmentationNode, segIds, labelmapVolumeNode, referenceVolumeNode)
slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsBinaryLabelmapRepresentationToFiles(dst_patient_dir, segmentationNode, segIds, “seg.nii.gz”, True)
Exporting the volume was the most straightforward part. slicer.util.exportNode does the job.