Changing the Scalar Values of a vtkImageReslice Object in a Pipeline

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)

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.

Thanks. I understand.