I have a lot of label map volume, and I would like to convert all to poly data vtk files. After googling, ITK-SNAP could help to export to vtk file, but could not run in batch script mode. 3D slicer’s ModelMaker could also do this, and it’s possible run a script. For now, what I have done:
for seg_filename in seg_filenames:
seg_nodename = seg_filename.split('/')[-1].split('.')[0]
img_node = slicer.util.loadVolume(img_filename)
label_node = slicer.util.loadLabelVolume(seg_filename)
parameters = dict()
parameters['InputVolume'] = label_node.GetID()
result_model = slicer.vtkMRMLModelHierarchyNode()
result_model.SetName(seg_nodename)
slicer.mrmlScene.AddNode(result_model)
parameters['ModelSceneFile'] = result_model.GetID()
parameters['Name'] = seg_nodename
modelmaker = slicer.modules.modelmaker
slicer.cli.run(modelmaker, None, parameters)
I’m stuck at how to save the result. I can use slicer.saveNode(node, filename, properties={})
to save a single node, but I don’t what to pass to node
.
It would be great how ModelMaker converts volume to model using VTK or ITK internally, then I could write python script using VTK or ITK directly.