#Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentationNode”)
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment(“bone”)
#Create 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(masterVolumeNode)
Occuring errors for all effects on apply line
#Thresholding
modifierLabelmap.GetImageToWorldMatrix(originalImageToWorldMatrix)
AttributeError: ‘NoneType’ object has no attribute ‘GetImageToWorldMatrix’
smoothing
modifierLabelmap.DeepCopy(smoothingFilter.GetOutput())
AttributeError: ‘NoneType’ object has no attribute ‘DeepCopy’
Probably you try to store results of tens or hundreds of iterations in the scene. During this you run out of physical memory and everything slows down due to starting swapping data between RAM and physical disk. To avoid this, at the end of each iteration, write the results to file then delete the result nodes (or reuse them in the next iteration).
Ok not so much iterations in my case, I need your help.
I tryed it without saving any results, just for testing iteration process.
First iteration takes 18 seconds, the second 1min14 ! and after I stop it before overheating
This confirms that the problem is that you run out of RAM.
Your script still does not free up memory because you need to delete display nodes and all filters. It could be simpler to get it right, if you create nodes and filters once and then update them in each iteration.