# vtkImageReslice not working properly? ResliceAxes are set, but have no effect?

**URL:** https://discourse.vtk.org/t/vtkimagereslice-not-working-properly-resliceaxes-are-set-but-have-no-effect/7796
**Category:** Development
**Created:** [February 8, 2022, 8:25pm UTC](https://discourse.vtk.org/t/vtkimagereslice-not-working-properly-resliceaxes-are-set-but-have-no-effect/7796 "2022-02-08T20:25:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MJJ](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b487fb/32.png) [@MJJ](https://discourse.vtk.org/u/MJJ)
#### Post date: [February 8, 2022, 8:25pm UTC](https://discourse.vtk.org/t/vtkimagereslice-not-working-properly-resliceaxes-are-set-but-have-no-effect/7796/1 "2022-02-08T20:25:33Z")

</div>

I have a `vtkImageData` called `img` that I want to use the `vtkImageReslice` algorithm on.

I want to reslice this image data to create a subimage that has its voxels aligned to a different coordinate system.

To do this i am using the following code:

```auto
reslice = vtk.vtkImageReslice()
reslice.SetInterpolationModeToLinear()
reslice.SetResliceAxes(get_subimg_rotation_matrix4x4())
reslice.SetResliceAxesOrigin(get_subimg_origin())
reslice.SetOutputOrigin(get_subimg_origin())
dims = get_subimg_dimensions()
reslice.SetOutputExtent(0, dims[0]-1, 0, dims[1]-1, 0, dims[2]-1)
reslice.SetOutputSpacing(get_subimg_spacing())
transform = vtk.vtkTransform()
transform .SetMatrix(get_subimg_rotation_matrix4x4())
reslice.SetResliceTransform(transform.GetInverse())
reslice.SetInputData(img)
reslice.Update()
subimg = reslice.GetOutput()

```

Here, get\_subimg\_rotation\_matrix4x4() just returns a rotation matrix that defines the reslice axes, like:

```auto
[
  [cos(theta), -sin(theta), 0.0, 0.0],
  [sin(theta), cos(theta), 0.0, 0.0],
  [0.0, 0.0, 1.0, 0.0],
  [0.0, 0.0, 0.0, 1.0]
]

```

When theta=0, i.e. the reslice axes are the identity matrix and therefore aligned with `img`, it works.

However, even when `theta` is nonzero, the `subimg` is not aligned with these reslice axes. Its as if the reslice axes were again the identity matrix.

Anyone have an example that can accomplish what I am trying to do?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [February 9, 2022, 9:21pm UTC](https://discourse.vtk.org/t/vtkimagereslice-not-working-properly-resliceaxes-are-set-but-have-no-effect/7796/2 "2022-02-09T21:21:53Z")

</div>

vtkImageReslice can be used in a few distinct ways and it is hard to figure out which combination of inputs and outputs are valid. It also matters in what order you set your inputs. For example, if you set reslice axes but then later set a reslice transform then your reslice axes inputs may be discarded.

To see valid usages of the filter, you can have a look at VTK examples, VTK tests, and VTK-based applications (for example some commonly used image resampling functions in 3D Slicer are available [here](https://github.com/Slicer/Slicer/blob/master/Libs/vtkSegmentationCore/vtkOrientedImageDataResample.cxx)).
