# Changing the Scalar Values of a vtkImageReslice Object in a Pipeline

**URL:** https://discourse.vtk.org/t/changing-the-scalar-values-of-a-vtkimagereslice-object-in-a-pipeline/2584
**Category:** Support
**Created:** [February 11, 2020, 9:42pm UTC](https://discourse.vtk.org/t/changing-the-scalar-values-of-a-vtkimagereslice-object-in-a-pipeline/2584 "2020-02-11T21:42:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MichelleKline](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michellekline/32/2155_2.png) [@MichelleKline](https://discourse.vtk.org/u/MichelleKline)
#### Post date: [February 11, 2020, 9:42pm UTC](https://discourse.vtk.org/t/changing-the-scalar-values-of-a-vtkimagereslice-object-in-a-pipeline/2584/1 "2020-02-11T21:42:15Z")

</div>

Hello,  
I am using vtkImageReslice to reslice a volume. I do the reslicing by controlling the resliceAxes of the vtkImageReslice object. Each time a “take a new slice” (ie, change the resliceAxes), I perform some calculations to update the scalar values of that slice. My hope is that these values will get saved in the vtkImageReslice object, so that I can access these updated values the next time I access this slice. After making the changes, I use GetPointData().GetScalars().Modified() on the vtkImage object that is output from the vtkImageReslice. However, the changes to the scalars at each slice go away after I make any changes to the resliceAxes. They don’t “stick”.  
Below is an example. Can anyone tell me what I need to do to make the changes to the scalars “stick”?

Many thanks,  
Michelle K.

```
# helper function: returns the numpy ndarray associated with the provided vtkImageData object
def vtk_image_to_numpy_array(vtk_image):
    numpy_array_shape = tuple(reversed(vtk_image.GetDimensions()))
    numpy_array = vtk.util.numpy_support.vtk_to_numpy(vtk_image.GetPointData().GetScalars()).reshape(numpy_array_shape)
    return numpy_array

# here I create a new vtkImageReslice object and pipe into it the output
# from vtkDICOMImageReader
testReslice = vtk.vtkImageReslice()
testReslice.SetInputConnection(reader.GetOutputPort())

# initialize resliceAxes to identity matrix
testResliceAxes = vtk.vtkMatrix4x4()
testResliceAxes.Identity()
testReslice.SetResliceAxes(testResliceAxes)
testReslice.Update()

# let's grab the z-coordinate of the origin of the current slice and save it so
# we can come back to this slice
z = testReslice.GetResliceAxes().GetElement(2, 3)
print(z) # <=== Answer: 0.0
    
# check the scalar range of this slice
print(testReslice.GetOutput().GetScalarRange()) # <=== Answer: (0.0, 1945.0)
    

# change the value of the scalars in this slice
reslice_image = testReslice.GetOutput()
reslice_image_NP = vtk_image_to_numpy_array(reslice_image)
reslice_image_NP[:] = 37.0
reslice_image.GetPointData().GetScalars().Modified()
testReslice.Update()

# check the scalar range of this slice
print(testReslice.GetOutput().GetScalarRange()) # <=== Answer: (37.0, 37.0)

# move to a different slice by changing the resliceAxes
testReslice.GetResliceAxes().SetElement(2, 3, 1.5)
testReslice.Update()

# check the scalar range of this slice
print(testReslice.GetOutput().GetScalarRange()) # Answer: (0.0, 1945.0)

# move back to the original slice
testReslice.GetResliceAxes().SetElement(2, 3, z)
testReslice.Update()

# check the scalar range of this slice
print(testReslice.GetOutput().GetScalarRange()) # Expected answer: (37.0, 37.0). Actual answer: (0.0, 1945.0)
```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 12, 2020, 2:08pm UTC](https://discourse.vtk.org/t/changing-the-scalar-values-of-a-vtkimagereslice-object-in-a-pipeline/2584/2 "2020-02-12T14:08:21Z")

</div>

In VTK, manual changes to a filter’s outputs will never “stick”. Data never flows from the output back into the filter. In order for changes to stick, the changes have to be made to the input.

---

<div class="post-metadata">

### Author: ![MichelleKline](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michellekline/32/2155_2.png) [@MichelleKline](https://discourse.vtk.org/u/MichelleKline)
#### Post date: [February 12, 2020, 3:36pm UTC](https://discourse.vtk.org/t/changing-the-scalar-values-of-a-vtkimagereslice-object-in-a-pipeline/2584/3 "2020-02-12T15:36:27Z")

</div>

Thanks. I understand.
