register.dat


text originating from Patrick Schikowski

register.dat is a 4x4 matrix, since it is not possible to encode a complete affine transformation (translation, scaling and rotation) in a 3x3 matrix. At the beginning you have separated matrices for the translation, the scaling and rotation. They are encoded like this:

Translation T =
(1,0,0,0)
(0,1,0,0)
(0,0,1,0)
(tx,ty,tz,1)

The translation vector is therefore placed in the last line of the matrix, the rest looks like a unit matrix. The scaling matrix is:

Scaling S =
(sx,0,0,0)
(0,sy,0,0)
(0,0,sz,0)
(0,0,0,1)

The rotation matrix is somehow more complicated and results from 3 separated rotation matrices, one for the rotation around each axis (x,y,z). Put together the rotation is encoded in the upper left 3x3 matrix. For details see the (computer graphics) literature.

Rotation R =
(r1,r2,r3,0)
(r4,r5,r6,0)
(r7,r8,r9,1)
(0, 0, 0, 1)

Luckily one can multiply the matrices together. If you do it in the right way, you will end up with one transformation matrix, the one freesurfer offers:

A = T * S * R

In A everything is included, the translation, the scaling and the rotation. It doesn't really matter that the matrix is 4x4, but of course you can only multiply it with a 4-dimensional vector for transformation purposes. To do so, you just have to expand the familiar 3-dimensional vector by one dimension and put in a 1 at the 4th dimension.

Vector v =
(x)
(y)
(z)
(1)

Now you will be able to multiply this one with the 4x4 transformation matrix and you will end up with the transformed point. You just have to ignore the 4th dimension of the vector, or you can change it back to a 3-dimensional one, by just cutting away the 4th dimension.

v * A = v_transformed