# Trying to update a slicer volume node from SimpleITKImage

**URL:** <https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032>\
**Category:** Support\
**Tags:** mrml, sitk\
**Created:** [February 6, 2018, 11:59am UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032 "2018-02-06T11:59:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![drusmanbashir](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/drusmanbashir/32/1282_2.png) [@drusmanbashir](https://discourse.slicer.org/u/drusmanbashir)\
**Post date:** [February 6, 2018, 11:59am UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/1 "2018-02-06T11:59:36Z")

</div>

Operating system: Window 7  
Slicer version: 4.8.1

Hi All,

I am a newbie. I am trying to develop a segmentation module using python. The main function takes as input a vtkMRMLLabelMapVolumeNode and a vtkMRMLScalarVolumeNode as well as an ‘outputVolumeNode’ which is a newly created (in slicer gui) vtkMRMLLabelMapVolumeNode. The algorithm produces a new label map volume (a numpy array) based on the input volume and labelmap and is trying to push the new label map volume into the output node as so:

sitkImageOutput = sitk.GetImageFromArray(numpyArray)  
sitkUtils.PushVolumeToSlicer(sitkImageOutput,outputVolumeNode)

But nothing happens - the outputVolumeNode inside slicer remains empty. Is there an update function or something i am missing?

Thanks

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 6, 2018, 4:54pm UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/2 "2018-02-06T16:54:09Z")

</div>

You could play with the SimpleFilters module and try using the same approach as is used there:

> <https://github.com/SimpleITK/SlicerSimpleFilters/blob/master/SimpleFilters/SimpleFilters.py#L476-L492>

---

<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 6, 2018, 10:58pm UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/3 "2018-02-06T22:58:09Z")

</div>

`numpyArray` does not specify image geometry (origin, spacing, axis directions). You have to call `outim.CopyInformation(some_reference_image)` or set the image geometry some other way.

> [@drusmanbashir](#):
>
> outputVolumeNode inside slicer remains empty

What is empty? Does not show up in slice viewer? If you go to Volumes module, what do you see in Volume Information section? If you open the Histogram at the bottom of the module GUI, do you see a histogram there?

---

<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 6, 2018, 11:06pm UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/4 "2018-02-06T23:06:06Z")

</div>

Maybe you have just forgot to show the created volume in the slice viewers. This code works for me:

```
import numpy as np
import sitkUtils
numpyArray = np.random.randint(0,10,[30,40,50])

sitkImageOutput = sitk.GetImageFromArray(numpyArray)
volumeNode = sitkUtils.PushVolumeToSlicer(sitkImageOutput,None)
slicer.util.setSliceViewerLayers(background=volumeNode)
```

---

<div class="post-metadata">

**Author:** ![drusmanbashir](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/drusmanbashir/32/1282_2.png) [@drusmanbashir](https://discourse.slicer.org/u/drusmanbashir)\
**Post date:** [March 4, 2018, 3:48pm UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/5 "2018-03-04T15:48:49Z")

</div>

Eventually setting origin and spacing got the code working like so:

```
  sitkUtils.PushVolumeToSlicer(sitkImageOutput,outputVolumeNode)
  outputVolumeNode.SetOrigin(inputVolumeNode.GetOrigin())
  outputVolumeNode.SetSpacing(inputVolumeNode.GetSpacing())
```

---

<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 4, 2018, 9:29pm UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/6 "2018-03-04T21:29:44Z")

</div>

Thanks for the update. Yes, numpy arrays cannot store image geometry, so you have to define the image geometry by setting origin, spacing, and axis directions in your SimpleITK image or Slicer volume node.

---

<div class="post-metadata">

**Author:** ![Jan\_Alexander](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jan_alexander/32/6831_2.png) [@Jan\_Alexander](https://discourse.slicer.org/u/Jan_Alexander)\
**Post date:** [March 1, 2021, 11:07am UTC](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032/7 "2021-03-01T11:07:09Z")

</div>

Thank you, I was able to get it working eventually with

`slicernb.MatplotlibDisplay(matplotlib.pyplot)`
