Heya! I am trying to work with the closed surface representation. Manually I can get the results I want. With code it seems as if some of the steps I want it to perform are lost or never occur.
Steps
1. Create a segmentation, set name/color
2. Using the SegmentationEditor set threshold min/max
3. Closed Surface Representation (1.5x Oversampling, 0 joint smoothing, 0 smoothing factor, 0 decimation)
4. Using the SegmentationEditor set median smoothing 2mm to this segmentation
5. Update the Closed Surface Representation (1.5x Oversampling, 1 joint smoothing, 1 smoothing factor, 0.9 decimation)
Essentially, I want to smooth the representation that isn’t decimated. After smoothing, decimate it. I imagine there must be a way to update the surface representation, but I can’t seem to find the necessary snippet to do this. I would appreciate any and all direction on the approach
# Access segmentation module
slicer.util.selectModule('Segment Editor')
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(seriesVolumeNode)
# Create spine segment
segmentTypeID = "Spine"
newSegment = slicer.vtkSegment()
newSegment.SetName(segmentTypeID)
newSegment.SetColor([0.89, 0.85, 0.78])
segmentationNode.GetSegmentation().AddSegment(newSegment,segmentTypeID)
# Create segment editor widget to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
# Access segment editor node
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(seriesVolumeNode)
# Segment Editor Effect: Thresholding
segmentEditorWidget.setActiveEffectByName("Threshold")
thresholdEffect = segmentEditorWidget.activeEffect()
thresholdEffect.setParameter("MinimumThreshold","90")
thresholdEffect.self().onApply()
thresholdEffect.setParameter("MaximumThreshold","1600")
thresholdEffect.self().onApply()
# Create Closed Surface Representation
segmentationNode.GetSegmentation().SetConversionParameter("Oversampling factor", "1.5")
segmentationNode.GetSegmentation().SetConversionParameter("Joint smoothing", "0.00")
segmentationNode.GetSegmentation().SetConversionParameter("Smoothing factor", "0.00")
segmentationNode.GetSegmentation().SetConversionParameter("Decimation factor", "0.00")
segmentationNode.CreateClosedSurfaceRepresentation()
# Segment Editor Effect: Smoothing
segmentEditorWidget.setActiveEffectByName("Smoothing")
smoothingEffect = segmentEditorWidget.activeEffect()
# 2mm MEDIAN Smoothing
smoothingEffect.setParameter("SmoothingMethod", "MEDIAN")
smoothingEffect.self().onApply
smoothingEffect.setParameter("KernelSizeMm", 2)
smoothingEffect.self().onApply
# Update Closed Surface Representation
segmentationNode.GetSegmentation().SetConversionParameter("Oversampling factor", "1.5")
segmentationNode.GetSegmentation().SetConversionParameter("Joint smoothing", "1.00")
segmentationNode.GetSegmentation().SetConversionParameter("Smoothing factor", "1.00")
segmentationNode.GetSegmentation().SetConversionParameter("Decimation factor", "0.90")
# Update the smoothed closed surface representation some how