# How to convert TrakEM2 transform to rotation angle and x,y translations

Hi all,

I’m using Fiji/ ImageJ 1.52p to create a new TrakEM2 project, in order to register stack of images. That parts works great! Now I would need to take the registration parameters and convert them to rotation angle + x,y translations, to be used in another system. Any ideas or tips how to do this? I tried to find some documentation of how to do it, or how the transform matrix works, but I couldn’t find anything, so if anyone can point me to right direction where I could find any documentation, that would be much appreciated. Below is example of project xml file that I was looking at… my planned approach is to take the transform=“matrix(1.0,0.0,-0.0,1.0,53.0,72.0)” part, and convert that to rotation angle + x,y, if possible.

Also, I’m also open for other ideas of how to do the same (rigid registration + getting the rotation angle + x,y), without using TrakEM2, if anyone has done similar thing already.

Here is a clip from TrakEM2 project.xml:
<t2_patch
oid=“33”
width=“949.0”
height=“901.0”
transform=“matrix(1.0,0.0,-0.0,1.0,53.0,72.0)”
title=“image_file.png”
type=“4”
file_path=“C:/work/image_file.png”
style=“fill-opacity:1.0;stroke:#ffff00;”
o_width=“949”
o_height=“901”
min=“0.0”
max=“255.0”
mres=“32”
>

Hello,

Usually this kind of transformation can be written in the shape of a 3x3 matrix, in your case it would look like this:

``````trsf = [ [1.0, -0.0, 53.0],
[0.0,  1.0, 72.0],
[0.0,  0.0,  1.0] ]
``````

(it is usual to omit the last line since it is always the same value).
Note that in your case, your matrix only have an `x` and a `y` translation, no rotation.
From such matrices you can express any linear transformation (more in-depth information there or there).

Now, if you want to extract the rotation and the translation from that matrix you can use the following python package: transformations from Christoph Gohlke and more specifically the function `decompose_matrix`. Though one has to be careful since this library is designed for 3D transformations and the function is expecting 4x4 matrices as an input. I would rewrite the matrices accordingly, for example, in your case:

``````trsf_3D = [ [1.0, -0.0, 0.0, 53.0],
[0.0,  1.0, 0.0, 72.0],
[0.0,  0.0, 1.0,  0.0],
[0.0,  0.0, 0.0,  1.0] ]
``````

I hope that helps,
Léo

Léo, thank you so much for your answer. I’m new to transformations, and image manipulation in general, and this really helps me into right direction!
-Antti