slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode, seg)
Traceback (most recent call last):
File “”, line 1, in
TypeError: arguments do not match any overloaded methods
You need to make sure the arguments match one of these.
Also the functions are static, so it’s possible that the error you get is because in python when you call a member function the first argument that is passed is self. Try to call the function as static, like this:
sorry but i need more help in this, actually im trying this simple code from the nightly documentation.
Create a segmentation from a labelmap volume and display in 3D
labelmapVolumeNode = getNode(‘label’)
seg = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLSegmentationNode’) slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode, seg)
seg.CreateClosedSurfaceRepresentation()
slicer.mrmlScene.RemoveNode(labelmapVolumeNode)
Do you have a labelmap node with the name ‘label’ in your scene?
Is labelmapVolumeNode a valid labelmap volume node?
What do you see on the console if you type labelmapVolumeNode and press enter?
When I pass None as the first argument to the ImportLabelmapToSegmentationNode call I get the error you’re seeing, but if I pass a valid volume node, it returns True.
Did the label map volume load? What’s the value of “success”?
# myScript
# to run: ~/sw/Slicer-4.8.1/Slicer --no-main-window --python-script myScript.py "
from __main__ import vtk, qt, ctk, slicer
from copy import deepcopy
import Tkinter, tkFileDialog, sys ,math
import os, re , time , datetime
import sitkUtils, numpy as np, SimpleITK as sitk
from shutil import copyfile
print(" myScript ")
[success, labelmapVolumeNode] = slicer.util.loadVolume("./myImg-label.nrrd", returnNode=True)
print ("labelmapVolumeNoderesult : " + str(success))
segVolumeNode = slicer.vtkMRMLSegmentationNode() slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode,segVolumeNode)
#slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode(labelmapVolumeNode, segVolumeNode)
print(" All tasks are done! ")
exit()
And here is the output:
Slicer --no-main-window --python-script ./myScript.py
Number of registered modules: 150
Number of instantiated modules: 150
Number of loaded modules: 150
myScript
Loaded volume from file: ~/myImg-label.nrrd.
Dimensions: 80x80x20. Number of components: 1. Pixel type: short.
"Volume" Reader has successfully read the file "./myImg-label.nrrd" "[0.02s]"
labelmapVolumeNoderesult : True
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "./myScript.py", line 20, in <module> slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(labelmapVolumeNode,segVolumeNode)
TypeError: arguments do not match any overloaded methods
It is not enough to create the segmentation node but you need to also add to the scene. You can use slicer.mrmlScene.AddNewNodeByClass to create a node and add it to the scene in one step.
slicer.util.loadVolume loads file as scalar volume, while ImportLabelmapToSegmentationNode expects a labelmap volume; you need to use slicer.util.loadLabelVolume instead
Relative path was used for the input image. I’m not sure what is the working directory of Slicer. It is safer to use absolute path.
After fixing these issues, a full working example:
It is not enough to create the segmentation node but you need to also add to the scene. You can use slicer.mrmlScene.AddNewNodeByClass to create a node and add it to the scene in one step.
I thought we don’t need a scene when we run from a script, I was wrong.
slicer.util.loadVolume loads file as scalar volume, while ImportLabelmapToSegmentationNode expects a labelmap volume; you need to use slicer.util.loadLabelVolume instead
Modules usually require all input and output nodes to be in the same scene. Without a scene, you cannot specify parent transforms or any other relationship between nodes.