# How to calculate the reverse 3d affine transform?

**URL:** https://discourse.itk.org/t/how-to-calculate-the-reverse-3d-affine-transform/4916
**Category:** Algorithms
**Tags:** registration, python
**Created:** [April 15, 2022, 8:26am UTC](https://discourse.itk.org/t/how-to-calculate-the-reverse-3d-affine-transform/4916 "2022-04-15T08:26:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yding58](https://discourse.itk.org/letter_avatar_proxy/v4/letter/y/f0a364/32.png) [@yding58](https://discourse.itk.org/u/yding58)
#### Post date: [April 15, 2022, 8:26am UTC](https://discourse.itk.org/t/how-to-calculate-the-reverse-3d-affine-transform/4916/1 "2022-04-15T08:26:18Z")

</div>

Hi all,

I tried to calculate the reverse affine transform matrix and the returned translation vector is always wrong, which bother me a lot. Anyone has any ideas? I appreciate for any suggestions. Thank you!

Here are some details steps I did:  
Assume I have two 3d images, A & B. I’ve calculated the transform from A to B and get a 12d vector (V). Now I want to get the transform matrix for B-\>A directly from the learned 12d vector: V.

I know the first 9 elements corresponding to M matrix, and the last 3 corresponding to the translation vector.

So I calculated the reverse M matrix as reverse(M) and reversed translation vector as -np.matmul(reverse(M), V(-3:)) and it turned out the reversed translation vector is wrong. May anyone know why this happens? Thank you!

---

<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: [April 15, 2022, 3:14pm UTC](https://discourse.itk.org/t/how-to-calculate-the-reverse-3d-affine-transform/4916/2 "2022-04-15T15:14:44Z")

</div>

Have you tried simply negating the translation (instead of multiplying it with the inverse of rotation/scaling/shear)? Have you tried appending 0 0 0 1 as the fourth row and then inverting the resulting 4x4 matrix? If you are using [itk::AffineTransform](https://itk.org/Doxygen/html/classitk_1_1AffineTransform.html) class, you can use [GetInverse()](https://itk.org/Doxygen/html/classitk_1_1Transform.html#a0d6329123e9c1347473c9e034ff172c9) method.
