Is there a way to create a label map node from a segmentation node? I know I can go the other way (from a label map to a segmentation), but I can’t seem to find a way to do the opposite. If this is not possible is there a way to at least get the array underlying the segmentation node? I know I can get an oriented image data, but if I do slicer.util.array on the oriented image data, nothing is returned.
You can also reach this function (i.e. Segmentations module import/export) from the Data module (right-click the segmentation), and in Segment Editor as an option for the Segmentations button.
You can always use help() function in Python to get documentation, for example:
help(slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode)
To create a custom Segment Editor effect, use ExtensionWizard module and choose ScriptedSegmentEditorEffect module template. It creates a fully functional effect that uses SimpleITK and you just have to replace the core of it to do what you need.
@cpinter Would you please help explain this to me?
inside here:
slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsToLabelmapNode(segmentationNode, segs, tmpLabelmapNode, masterVolumeNode)
where segs has to be an vtk.vtkStringArray() and the segs may be obtained by:
But while I try to get the selected segment-ID through:
segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
selectedSegmentID = self.scriptedEffect.parameterSetNode().GetSelectedSegmentID()
where I just got a simple string for selectedSegmentID
How can I get a vtk.vtkStringArray for this selectedSegmentID or any easy conversion?
The constant string is the name of the node reference role. You can get the reference volume node like this: segmentationNode.GetNodeReference(slicer.vtkMRMLSegmentationNode.GetReferenceImageGeometryReferenceRole())
Somehow this code works in the nightly, but when I do this in 4.10.2 I get error (InsertNextValue expects a string). If I do pass 0 as a string, I get a crash. The correct way to initialize that array, as I understand it, is the following: