# help in applying rotation using Affinematrix

**URL:** https://discourse.itk.org/t/help-in-applying-rotation-using-affinematrix/3592
**Category:** Algorithms
**Tags:** python, simpleitk
**Created:** [November 3, 2020, 11:26am UTC](https://discourse.itk.org/t/help-in-applying-rotation-using-affinematrix/3592 "2020-11-03T11:26:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![prms](https://discourse.itk.org/user_avatar/discourse.itk.org/prms/32/1526_2.png) [@prms](https://discourse.itk.org/u/prms)
#### Post date: [November 3, 2020, 11:26am UTC](https://discourse.itk.org/t/help-in-applying-rotation-using-affinematrix/3592/1 "2020-11-03T11:26:49Z")

</div>

I am using this AffineMatrix to rotate the image by 90 degrees.  
array([[1., 0., 0., 0.],  
[0., 0., -1., 0.],  
[0., 1., 0., 0.],  
[0., 0., 0., 1.]])

When I apply this transformation to image(left is the original one and the right is the result of transformation), I am getting this output.

 ![rotation_error](https://discourse.itk.org/uploads/default/original/2X/6/694353d79cc4ce0b3359ce30fce5fbb26e09b6cc.png)

What I was expecting is this:

 ![rotation_error1](https://discourse.itk.org/uploads/default/original/2X/7/7ec4dd93db5a4ad25948e8af2ee3b8cdc89efa7e.png)

I have a rough idea this might be due to direction cosine. Since affine matrix is a combination of multiple transforms, I was trying to apply rotation using sitk’s AffineTransform. Can this be done? Am I missing something here?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [November 3, 2020, 3:02pm UTC](https://discourse.itk.org/t/help-in-applying-rotation-using-affinematrix/3592/2 "2020-11-03T15:02:17Z")

</div>

Hello @prms,

Your understanding of the resampling operation in SimpleITK is incorrect. To understand the concept of images as a spatial object and how resampling is performed, please go over the [fundamental concepts](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html) the [Transforms and Resampling](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/21_Transforms_and_Resampling.ipynb) notebook and the [Data Augmentation](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/70_Data_Augmentation.ipynb) notebook.
