Dear community,
I’m trying to apply Wrap Solidify in a Python script following the instructions provided here. I’ve attached the code:
Create a segmentation node
segmentationNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentationNode”)
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)Create segment editor
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentEditorNode”)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
Configure segment editor for thresholding
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setSourceVolumeNode(masterVolumeNode)Apply Threshold Effect
segmentEditorWidget.setActiveEffectByName(“Threshold”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“MinimumThreshold”, 30)
effect.setParameter(“MaximumThreshold”, 800)
effect.self().onApply()
print(“Threshold effect applied successfully.”)Apply Islands Effect
segmentEditorWidget.setActiveEffectByName(“Islands”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“MinimumSize”, 1000) # Minimum size in mm³ for islands to keep (adjust as needed)
effect.setParameter(“MaxIslandCount”, 0) # Set to 0 to remove all islands smaller than the size threshold
effect.self().onApply()
print(“Islands effect applied successfully.”)Apply Wrap Solidify Effect
segmentEditorWidget.setActiveEffectByName(“Wrap Solidify”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“OuterSurface”, True)
effect.setParameter(“CarveHoles”, True)
effect.setParameter(“SmoothingFactor”, 25) # Corrected parameter
effect.self().onApply()
print(“Wrap Solidify effect applied successfully.”)
However, I’m encountering the following error:
Traceback (most recent call last):
File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 252, in onApply
self.logic.applyWrapSolidify()
File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 338, in applyWrapSolidify
regionPd = self._getInitialRegionPd()
File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 526, in _getInitialRegionPd
raise ValueError(“Region segment cannot be the same segment as the current segment”)
ValueError: Region segment cannot be the same segment as the current segment
Does anyone have suggestions on how to resolve it?