Load a .stl file and save it to a binary label map through

Good afternoon,
I’m trying to save a big bunch of .stl files to .nrrd binary label maps through python. I’m using the code below:

volume = slicer.util.loadVolume('C:\\Users\mreib\OneDrive - upf.edu\Burdeos\images\Bordeaux_Case1\image.mha', returnNode=True)
segmentation = slicer.util.loadSegmentation('C:\Users\mreib\OneDrive - upf.edu\Burdeos\Observer_1\case1_1.stl', returnNode=True)

labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')

ids = vtk.vtkStringArray()
seg = getNode('case1_1')
seg.GetDisplayNode().GetVisibleSegmentIDs(ids)

slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode(seg, ids, 
labelmapVolumeNode, volume)

I keep getting the following error.

Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: no overloads of ExportSegmentsToLabelmapNode() take 2 arguments

Thanks in advance!

Type help(slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode) in the Python console or read the API documentation to get information on what parameters are needed.

You may also find the numerous segmentation examples in script repository useful.

1 Like

I have managed to solve it, but thank you very much anyways! Now I have a problem running the script from the python interactor. I suppose it isn’t as simple as using ‘python Myscript.py’.

It is almost as simple. You can use PythonSlicer Myscript.py (there are a couple of variants - see here).

Thanks for your help! I’m sorry for asking such simple questions.

1 Like

2 posts were split to a new topic: Combine STLs and export as NRRD