vtkMRMLScalarVolumeNode to SimpleITK image

Hello all in the Slicer Forum.

I write an python Extension for Slicer and have the following Code that produces an error in the last line:

  for i in range(0, len(inputPlanes)):
    n = slicer.vtkMRMLScalarVolumeNode()  
    tempVolName = "tempVol_" + str(i)

    ### Compute the temporal volume using the CLI module brainsresample
    cliParams = {'inputVolume': inputPlane.GetID(), 'referenceVolume': referenceVolume.GetID(), 'outputVolume' : n.GetID()}
    cliNode = slicer.cli.run(slicer.modules.brainsresample, None, cliParams)

    itkImageVolume = sitkUtils.PullFromSlicer(n.GetName()) # throws error

for the last line I get the following intepreter error:

Traceback (most recent call last):
File "D:/repositories/My Slicer Extention/StVRegistration/StVRegistration/StVRegistration/StVRegistration.py", line 176, in onApplyButton
logic.run(inputPlanes, self.referenceVolumeSelector.currentNode(), self.outputVolumeSelector.currentNode())
File "D:/repositories/My Slicer Extention/StVRegistration/StVRegistration/StVRegistration/StVRegistration.py", line 296, in run
tempPlaneVol = sitkUtils.PullFromSlicer(n.GetName())
File "C:\Program Files\Slicer 4.7.0-2017-06-26\bin\Python\sitkUtils.py", line 100, in PullFromSlicer
sitkimage = sitk.ReadImage(myNodeFullITKAddress)
File "C:\Program Files\Slicer 4.7.0-2017-06-26\lib\Python\Lib\site-packages\SimpleITK\SimpleITK.py", line 8335, in ReadImage
return _SimpleITK.ReadImage(*args)
RuntimeError: Exception thrown in SimpleITK ReadImage: D:\D\N\Slicer-1-build\SimpleITK\Code\IO\src\sitkImageReaderBase.cxx:264:
sitk::ERROR: Logic error!

However, if I type the same last line in the interactive python console in Slicer after performing the script of the module it works just fine. Does anybody know what is going on there?

For the CLI module brainsresample I need vtkMRMLScalarVolumeNodes as input but later I want to use simpleITK within the python script and therefor need SimpleITK images. How would I go about it?

What I try here is
Thanks for your Reply

Try adding wait_for_completion=True in the slicer.cli.run call.

That did help thank you. =)

1 Like