# Rotating an Oblique Image

**URL:** https://discourse.itk.org/t/rotating-an-oblique-image/2470
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [December 4, 2019, 4:09am UTC](https://discourse.itk.org/t/rotating-an-oblique-image/2470 "2019-12-04T04:09:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kleingeo](https://discourse.itk.org/user_avatar/discourse.itk.org/kleingeo/32/1114_2.png) [@kleingeo](https://discourse.itk.org/u/kleingeo)
#### Post date: [December 4, 2019, 4:09am UTC](https://discourse.itk.org/t/rotating-an-oblique-image/2470/1 "2019-12-04T04:09:19Z")

</div>

I have been trying to rotate an image that has quaterion coordinates and is in an oblique reference frame, but I am not entirely sure how this is done. When I apply the same rotations (two rotations about the x and y axes) to a non-oblique image, it ends up in the proper orientation. However, when trying with the image with the quaterion rotations, it ends up slightly off tilt (almost like a picture off center in a picture frame). The images in question are 3D images and I have been trying both the VersorTransform and the Eurler3DTransform for the rotations, but with no success with the oblique images.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 4, 2019, 3:02pm UTC](https://discourse.itk.org/t/rotating-an-oblique-image/2470/2 "2019-12-04T15:02:29Z")

</div>

Welcome to the community Geoff!

Some screenshots would be helpful to understand your problem.

---

<div class="post-metadata">

### Author: ![kleingeo](https://discourse.itk.org/user_avatar/discourse.itk.org/kleingeo/32/1114_2.png) [@kleingeo](https://discourse.itk.org/u/kleingeo)
#### Post date: [December 4, 2019, 4:11pm UTC](https://discourse.itk.org/t/rotating-an-oblique-image/2470/3 "2019-12-04T16:11:21Z")

</div>

Sure thing. Here is the snippet of code that I am using. Essentially I am rotating in two axis, and I have confirmed this does work when the images are not in an oblique view. The images are starting in ASL orientation and I am rotating them into SLA orientation. Below are the images with the quaternion values taken all screen shot from ITK-Snap. The left image is the one with the quaterion angles and the right is the one that worked properly.

```python
    euler = sitk.Euler3DTransform()
    euler.SetComputeZYX(True)
    a = np.array([[1., 0, 0],
                  [0, 0, 1.],
                  [0, -1., 0]])

    b = np.array([[0, 1., 0],
                  [-1., 0, 0],
                  [0, 0, 1.]])

    c = np.matmul(b, a)

    euler.SetMatrix(tuple(c.flatten()))
    euler.SetCenter(img_resampled.GetOrigin())

    old_direction = np.array(img.GetDirection()).reshape(3, 3)
    new_direction = np.matmul(c, old_direction)

    image_shape = img.GetSize()

    resample = sitk.ResampleImageFilter()
    resample.SetReferenceImage(img)

    resample.SetSize([image_shape[2], image_shape[0], image_shape[1]])
    resample.SetOutputDirection(tuple(new_direction.flatten()))
    
    resample.SetInterpolator(sitk.sitkLinear)
    resample.SetTransform(euler)

    img_resampled = resample.Execute(img)

```

![itk-snap%20bad%20rotation%20quaterion](https://discourse.itk.org/uploads/default/original/2X/b/b35409bd7578cc23e1f23b1321046d83f7d9d17c.png) ![itk-snap%20bad%20rotation](https://discourse.itk.org/uploads/default/original/2X/e/e7df9a3513c3cc46e834e9ce39ade07919fda408.png) ![itk-snap%20good%20rotation](https://discourse.itk.org/uploads/default/original/2X/f/f71bf8501fd56949823aead1734331a6db370ccb.png)
