Hello,
I have slicer version 4.10.2 r28257 installed on an iMac
I am trying to convert two volume nodes into a numpy 3d arrays, do some processing to them, and then convert the numpy arrays back into a volume. I tried the method as listed in the nightly documentation that Andras posted:
import numpy as np
import math
a = arrayFromVolume(input1Volume)
b = arrayFromVolume(input2Volume)
def some_func(x, y):
return y(x-y)
a = np.fromfunction(some_func,(30,20,15))
volumeNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLScalarVolumeNode’)
volumeNode.CreateDefaultDisplayNodes()
updateVolumeFromArray(volumeNode, a)
setSliceViewerLayers(background=volumeNode)
But for that, I got the error that “arrayFromVolume” global name not defined.
Then, I put slicer.util before what I took to be the slicer related commands, like so:
import numpy as np
import slicer.util
import math
a = slicer.util.arrayFromVolume(input1Volume)
b = slicer.util.arrayFromVolume(input2Volume)
def some_func(x, y):
return y(x-y)
a = np.fromfunction(some_func,(30,20,15))
volumeNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLScalarVolumeNode’)
volumeNode.CreateDefaultDisplayNodes()
slicer.util.updateVolumeFromArray(volumeNode, a)
setSliceViewerLayers(background=volumeNode)
After that, though, I got the error that ‘only integer scalar arrays can be converted to a scalar index’
The volumes are from DICOM files, but I (think?) I have them as mrml volume nodes in my script, since I used the Qt GUI to treat the DICOM files I select as inputs as volume nodes.
I tried the methods listed on this page, but I they either didn’t work or I implemented them incorrectly. Could you please advise me on how to fix this problem?
Thanks,
Timothy