# Getting vtkMRMLSliceNodeGreen, vtkMRMLSliceNodeRed, vtkMRMLSliceNodeYellow data into numpy array

**URL:** <https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422>\
**Category:** Development\
**Tags:** dicom\
**Created:** [February 24, 2020, 11:42pm UTC](https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422 "2020-02-24T23:42:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dataminer](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dataminer](https://discourse.slicer.org/u/dataminer)\
**Post date:** [February 24, 2020, 11:42pm UTC](https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422/1 "2020-02-24T23:42:51Z")

</div>

Hello Everyone

I am new to slicer.  
I can import NRRD file and see the 3 views (sagittal, coronal and transverse), and I can use 3DSlicer to save them as png file for each of the 3 views (by using ScreenCapture.ScreenCaptureLogic().captureSliceSweep). But I do not know how to get these values into numpy array. I think this is only giving me for one of the views,

```
refNodeName = 'knee'
        refPath = os.path.join(refPath, refNodeName + ".nrrd")
        slicer.util.loadNodeFromFile(refPath, 'VolumeFile')
        node=slicer.util.getFirstNodeByName(refNodeName)
        array = slicer.util.array(refNodeName)
        print(array.shape, array.ndim)

```

Is there a way to access the 3 views/planes and get the data into Numpy Array.  
Hope I could explain it properly.

Thanks

dm

---

<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:** [February 25, 2020, 3:00am UTC](https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422/2 "2020-02-25T03:00:50Z")

</div>

The best approach depends on what you would like to achieve. Could you give a bit more information about your use case? What would you like to do with the numpy array?

---

<div class="post-metadata">

**Author:** ![dataminer](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@dataminer](https://discourse.slicer.org/u/dataminer)\
**Post date:** [February 25, 2020, 2:01pm UTC](https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422/3 "2020-02-25T14:01:39Z")

</div>

Hello,

I can save it in a text file for further processing.  
I have been looking for code snippets which does this, but have not come across any.  
Can you please guide me to the right direction. I feel like perhaps this is something very standard but I do not know how to do it yet.

Also I am looking into loading 3D volume from NRRD file into numpy array or merging slices to generate the 3D volume, but that can be a separate topic.

Thanks!

dm

---

<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:** [February 25, 2020, 6:40pm UTC](https://discourse.slicer.org/t/getting-vtkmrmlslicenodegreen-vtkmrmlslicenodered-vtkmrmlslicenodeyellow-data-into-numpy-array/10422/4 "2020-02-25T18:40:36Z")

</div>

> [@dataminer](#):
>
> I can save it in a text file for further processing.

While it does not sound like a good idea (text representation for an image is extremely inefficient), you can certainly do this if you have your data in a numpy array. In my question I meant what you actually want to do (beyond writing to file).

> [@dataminer](#):
>
> Also I am looking into loading 3D volume from NRRD file into numpy array or merging slices to generate the 3D volume, but that can be a separate topic

This is already available. Check out [Slicer programming tutorials](https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials) and [Slicer script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository). If you have any questions then you can post them here.
