arrayFromVolume issue

I’ m trying to obtain the array of this volume, but i obtain some errors. Can you help me?

labeledImage = self.LabeledVolumeSelector.currentNode().GetImageData()
selectedImage = self.SelectedVolumeSelector.currentNode().GetImageData()

I tried to use slicer.util.arrayFromVolume but i obtain this error: TypeError: object of type 'vtkCommonDataModelPython.vtkImageData' has no len()

This is the code written in 3DSlicer 3.6, it may be helpful:

labeledImage = self.LabeledVolumeSelector.GetSelected().GetImageData()
selectedImage = self.SelectedVolumeSelector.GetSelected().GetImageData()
labeledArray = labeledImage.ToArray()
selectedArray = selectedImage.ToArray()
labeledSlice = vol[ijk[2],…]
selectedSlice = voll[ijk[2],…]

arrayFromVolume requires a MRML volume node as input. See examples in script repository.

If i want to get an array from the previous image there’s an another way to do that? I have to take necessarily that input, because LabeledVolumeSelector and SelectedVolumeSelector came from qMRMLNodeComboBox. I’m sorry but i’m not very expert

You can find detailed, step-by-step tutorials here:

1 Like