Hi!
I am trying to automatize some series of lung segmentation steps on 3D Slicer with using python scripts.
Currently I can resample my file using;
volumeNode = slicer.util.loadVolume(file)
emptyVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", "output volume")
slicer.util.mainWindow().moduleSelector().selectModule('ResampleScalarVolume')
params = {}
params["InputVolume"] = volumeNode
params["OutputVolume"] = emptyVolumeNode
params["outputPixelSpacing"] = (2,2,2)
resampleModule = slicer.modules.resamplescalarvolume
cliNode = slicer.cli.runSync(resampleModule,None,params)
Or add empty segmentations using;
slicer.util.mainWindow().moduleSelector().selectModule('Segmentations')
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode. SetReferenceImageGeometryParameterFromVolumeNode(emptyVolumeNode)
leftSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("left lung")
rightSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("right lung")
tracheaSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("trachea")
Also in Segment Editor, the “Smoothing” section I can use the smoothing tool like this;
segmentEditorWidget.setActiveEffectByName("Smoothing")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("SmoothingMethod", "CLOSING")
effect.setParameter("KernelSizeMm", 12)
effect.self().onApply()
However I am struggling to use “Threshold” and “Grow from seeds” parts. In Threshold part I want it to click the “Use for masking” button and in the Grow from seeds part I want it to first click “Initialize” then “Apply” button.
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold","-1024")
effect.setParameter("MaximumThreshold","-500")
effect.self().onApply()
For example this code sets correct threshold values but clicks “apply” instead of “use for masking” button.
I researched the script repository but wasn’t able to find anything. I would appreciate any help. Thanks!
Yusuf Utku Gül