Operating system: Ubuntu Linux 18 LTS
Slicer version: 4.9.0-2018-10-09 r27464
Hello,
I am currently doing the following manually using the GUI
- Load .tif stack, deselect labelmap and single image after clicking “show options”
- Volumes module: deactivate interpolate
- Crop volume module: create new volume, select input volume, fix ROI, select a region for cropping, deselect interpolated cropping and apply
- Create 3 new segmentations based on this cropped volume with different threshold values
- Create a closed surface with smoothing factor changed to 0.0
- Export stl files
I have a huge amount of data that i need to process in the same way, so i need to automate this process using the python interface. What i have currently is the code at https://gist.github.com/lassoan/1673b25d8e7913cbc245b4f09ed853f9 (thank you lassoan!) where only the first line of code differs so far.
[success, loadedVolumeNode] = slicer.util.loadVolume(stack.tiff, returnNode=True) ## Create segmentation segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode") segmentationNode.CreateDefaultDisplayNodes() # only needed for display segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(loadedVolumeNode) addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("pores") ## 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(loadedVolumeNode) ## Thresholding segmentEditorWidget.setActiveEffectByName("Threshold") effect = segmentEditorWidget.activeEffect() effect.setParameter("MinimumThreshold","100") effect.setParameter("MaximumThreshold","100") effect.self().onApply() ## Clean up segmentEditorWidget = None slicer.mrmlScene.RemoveNode(segmentEditorNode) ## Make segmentation results visible in 3D segmentationNode.CreateClosedSurfaceRepresentation() ## Make sure surface mesh cells are consistently oriented surfaceMesh = segmentationNode.GetClosedSurfaceRepresentation(addedSegmentID) normals = vtk.vtkPolyDataNormals() normals.AutoOrientNormalsOn() normals.ConsistencyOn() normals.SetInputData(surfaceMesh) normals.Update() surfaceMesh = normals.GetOutput() ## Write to STL file writer = vtk.vtkSTLWriter() writer.SetInputData(surfaceMesh) writer.SetFileName("something.stl") writer.Update()
This extracts a .stl file, which i cannot open. It looks like nothing is selected in the segmentation step, which i think is related to the labelmap during import of data.
So my question is, is there any documentation resource where i can find the necessary function calls and properties for this, or has someone else done anything similar? I am very grateful for any pointers in the right direction!
Best regards,
Johan