How to read data from a vtkMRMLScalarVolumeNode

Hi all,
I’m having some problem reading data in .nii format in a vtkMRMLScalarVolumeNode in python scripted module.
I currently use

data ,header= load(’/‘directoryodmydata’/Sag.nii.gz’)

to read data from my dataset, and since I have loaded my image in Slicer, I want to use a different approach by reading data from the node.
Is there any way to read both the data and the header from the vtkMRMLScalarVolumeNode? I tried but my code didn’t work. Does anyone know the way of implementing this?

Thanks for your time!
Andrea

I typically load volumes like this:

slicer.util.loadVolume('/path/to/volume')

Hi, thanks for reply and sorry for I didn’t make my question clear. I know how to load a Volume, but I have problem reading data from the node. For instance, I loaded a .nii file as a volume, then I want to read the data and header data from that volume. I don’t know which function to use. Can someone help with this?

Please specify what you mean by “reading” data from the node.

sorry for my poor english. I mean I can achieve things like this.
to load the data and header from a .nii file

You can get voxels as numpy array or get the volume as SimpleITK image as shown in several examples in the script repository.

Hi Andras,
If I load a vtkScalarVolume in Slicer. How can I read the header of this loaded volume within slicer if I dont want to read using nrrd.read(). I can get the data of volume using
slicer.util.arrayFromVolume( volumeNode )
but how can the header be read directly using vtkMRMLscalarvolume

regards,
Saima Safdar

Hi Andras,
If I load a vtkScalarVolume in Slicer. How can I read the header of this loaded volume within slicer if I dont want to read using nrrd.read(). I can get the data of volume using
slicer.util.arrayFromVolume( volumeNode )
but how can the header be read directly using vtkMRMLscalarvolume

regards,
Saima Safdar

You can get the image geometry (origin, spacing, and axis directions), voxel type, number of components, image type from the volume node. If you store other metadata in the header then you probably need to parse the header using pynrrd or similar packages.

What data do you need from the nrrd header?