# How to read data from a vtkMRMLScalarVolumeNode

**URL:** https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252
**Category:** Development
**Created:** [March 23, 2019, 10:13am UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252 "2019-03-23T10:13:24Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)
#### Post date: [March 23, 2019, 10:13am UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/1 "2019-03-23T10:13:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [March 23, 2019, 1:33pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/2 "2019-03-23T13:33:16Z")

</div>

I typically load volumes like this:

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

---

<div class="post-metadata">

### Author: ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)
#### Post date: [March 23, 2019, 2:05pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/3 "2019-03-23T14:05:50Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [March 23, 2019, 3:14pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/4 "2019-03-23T15:14:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)
#### Post date: [March 23, 2019, 3:24pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/5 "2019-03-23T15:24:23Z")

</div>

sorry for my poor english. I mean I can achieve things like [this.](http://loli.github.io/medpy/_modules/medpy/io/load.html)  
to load the data and header from a .nii file

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [March 23, 2019, 5:43pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/6 "2019-03-23T17:43:12Z")

</div>

You can [get voxels as numpy array](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.arrayFromVolume) or [get the volume as SimpleITK image](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Running_an_ITK_filter_in_Python_using_SimpleITK) as shown in several examples in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository).

---

<div class="post-metadata">

### Author: ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)
#### Post date: [August 18, 2021, 8:12am UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/7 "2021-08-18T08:12:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)
#### Post date: [August 23, 2021, 5:12am UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/8 "2021-08-23T05:12:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 23, 2021, 4:35pm UTC](https://discourse.slicer.org/t/how-to-read-data-from-a-vtkmrmlscalarvolumenode/6252/9 "2021-08-23T16:35:26Z")

</div>

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?
