Hi Andras,
I am trying to do the following
import segment to segmentationNode
create a new segment
copy the import segment to new segment
grow the newsegment with margin
When I do all this I do not retain the old imported segment. I could not find mistake. I am pasting code here. Could you please help me in this. Thank you
outputVolume.SetName("brain")
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
#segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(inputVolume)
# Create temporary segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
#segmentEditorWidget.setMasterVolumeNode(inputVolume)
#import volume to labelmap
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(outputVolume, segmentationNode)
segmentationNode.CreateClosedSurfaceRepresentation()
segmentEditorWidget.setCurrentSegmentID(segmentationNode.GetSegmentation().GetNthSegmentID(0))
segmentation = segmentationNode.GetSegmentation()
segmentation.AddEmptySegment("Skull")
#copy brain into this new segment
segmentEditorWidget.setActiveEffectByName("Logical operators")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("Operation", "UNION")
brain = segmentation.GetSegmentIdBySegmentName("brain")
skull = segmentation.GetSegmentIdBySegmentName("skull")
effect.setParameter("SelectedSegmentID", skull)
effect.setParameter("ModifierSegmentID", brain)
#segmentEditorWidget.setCurrentSegmentID(skull)
effect.self().onApply()
#grow the skull
segmentEditorWidget.setActiveEffectByName("Margin")
effect = segmentEditorWidget.activeEffect()
segmentEditorWidget.setSegmentationNode(segmentationNode)
#segmentEditorWidget.setCurrentSegmentID(skull)
segmentEditorWidget.setActiveEffectByName("Margin")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MarginSizeMm","4")
effect.setParameter("SelectedSegmentID", skull)
effect.self().onApply()