Hello everyone! hope you are doing well.
Well. I’m trying to assign my own segmentation algorithm to the input images and put the outoput back in segment editor to edit it. It would help me to improve my model.
I already installed jupyter extension, and followed the scripts commands Script repository — 3D Slicer documentation , but when I tried to edit the imported segmentation, it doesn’t works.
The code I used:
volume = slicer.util.getNode('patient_1') # imported manually
input_images = slicer.util.arrayFromVolume(volume) # (n, 512,512)
new_masks = np.array(mask_list) # generated from region growing # (n, 512,512)
''' Create Segmentation Node in scene '''
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
''' create a display '''
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(volume)
lung_segment = segmentationNode.GetSegmentation().AddEmptySegment("lung_segment")
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(volume)
segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName('lung_segment')
slicer.util.updateSegmentBinaryLabelmapFromArray(new_masks, segmentationNode, segmentId, volume)
It’s working, but I don’t know how to set the segmentation mask editable. Any suggestion?
Thanks in advance
Imported segmentation
Trying to edit with Paint:
Ps.: The Volume is a collection of images that I imported with the option single file unchecked.
Slicer Version: 4.13