I am trying to grow segments with the margin effect. I have a segmentation with 5 segments, all segments are supposed to grow by 1mm (with overlap).
This is how I use it in my script:
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(volumeNode)
segmentEditorWidget.setActiveEffectByName("Margin")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MarginSizeMm", 1.0)
effect.setParameter("ApplyToAllVisibleSegments", 1)
segmentEditorNode.SetOverwriteMode(2)
segmentEditorNode.SetMaskMode(0)
effect.self().onApply()
When i run this, the effect is applied only to the first segment in my segmentation, and it is applied 5 times to this segment. Instead I want the effect to be applied once to each segment. It works perfectly if I do this manually in the Segment Editor.
How can I solve this?