# For vtk 9.0.1, has vtkImageReslice use the direction of image?

**URL:** https://discourse.vtk.org/t/for-vtk-9-0-1-has-vtkimagereslice-use-the-direction-of-image/4981
**Category:** Support
**Created:** [January 11, 2021, 2:32pm UTC](https://discourse.vtk.org/t/for-vtk-9-0-1-has-vtkimagereslice-use-the-direction-of-image/4981 "2021-01-11T14:32:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [January 11, 2021, 2:32pm UTC](https://discourse.vtk.org/t/for-vtk-9-0-1-has-vtkimagereslice-use-the-direction-of-image/4981/1 "2021-01-11T14:32:03Z")

</div>

I am using `vtkImageReslice` in my project, and I find a stranger thing.

The direction of vtkImageData is not a identify matrix, thus I adjust the direction by:

```auto
    x = [0, 1, 0]
    y = [1, 0, 0]
    z = [0, 0, 1]
    image.SetDirectionMatrix(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2])

```

Then, the `vtkImageReslice` code is:

```auto
directionMatrix = image.GetDirectionMatrix()
center = image.GetCenter()
dirElement = [0]*9
directionMatrix.DeepCopy(dirElement, directionMatrix)

x = [dirElement[0], dirElement[3], dirElement[6]]
y = [dirElement[1], dirElement[4], dirElement[7]]
z = [dirElement[2], dirElement[5], dirElement[8]]

a = [x[0],x[1],x[2]]
b = [y[0],y[1],y[2]]
c = [z[0],z[1],z[2]]
axialElement = [
    a[0], b[0], c[0], center[0],
    a[1], b[1], c[1], center[1],
    a[2], b[2], c[2], center[2],
    0, 0, 0, 1
]

reslice = vtk.vtkImageReslice()
reslice.SetInputData(image)
reslice.SetAutoCropOutput(True)
reslice.SetOutputDimensionality(2)
reslice.SetInterpolationModeToCubic()
reslice.SetSlabNumberOfSlices(1)
reslice.SetOutputSpacing(0.35, 0.35, 0.35)

resliceAxes = vtk.vtkMatrix4x4()
resliceAxes.DeepCopy(axialElement)
reslice.SetResliceAxes(resliceAxes)
reslice.Update()

```

In the above code, I use the center and direction of `vtkImageData` to reslice the image, and the result is fine.

However, if I adjust the `vtkImageData` as following:

```auto
    x = [0, 1, 0]
    y = [1, 0, 0]
    z = [0, 0, -1] ########### the original is [0, 0, 1]
    image.SetDirectionMatrix(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2])

```

Then, the resliced image is all zero.

Then, I have a look into the source code of `vtkImageReslice`, in the `RequestInformation`, there is a piece of code:

```auto
// line 992
  double inCenter[3];
  for (i = 0; i < 3; i++)
  {
    inCenter[i] = inOrigin[i] + 0.5 * (inWholeExt[2 * i] + inWholeExt[2 * i + 1]) * inSpacing[i];
  }

```

When calculate the `inCenter`, it do not conside the direction of `vtkImageData`, thus the `image.GetCenter()` may be outside of `vtkImageReslice.outWholeExt`. And I think the may be the reason why `z=[0, 0, -1]` make the output of `vtkImageReslice` zeros.

I don’t know whether my guess is correct. Does anyone know whether the `vtkImageReslice` take the direction of `vtkImageData` into consider?
