[Insight-users] RE: Quaternion transformation

Lydia Ng lng at insightful . com
Wed, 5 Jun 2002 14:41:46 -0700


Buu,

> - the fourth parameter is 0.996219. This means cos(t/2) =3D=20
> 0.996219, then I
> can find the rotation angle t. Am I right?  How do we know=20
> the rotation
> axis?
> - the last three parameters are about the translation. How do=20
> we compute the
> translation vector?

Let the final parameters be p =3D array of 7 numbers
counting from 0.

Let rotation angle =3D t, then=20
 t =3D 2 * acos(p[3])

Let rotation axis =3D n (array of 3 numbers), then
=20
 n[0] =3D p[0] / sin(t/2)
 n[1] =3D p[1] / sin(t/2)
 n[2] =3D p[2] / sin(t/2)

Let translation vector =3D t (array of 3 numbers), then

 t[0] =3D p[4];
 t[1] =3D p[5];
 t[2] =3D p[6];

If you want a rotation matrix M instead of axis and angle
you can ask the transform for it.

Presuming you are using the Beta and not the latest cvs code
add the following lines after line 123 of MIRegistrationApp.cxx

  std::cout << "Rotation matrix: " << std::endl;
  std::cout <<=20
  =
m_Registrator->GetInternalRegistrationMethod()->GetMetric()->GetMapper()-=
>
   GetTransform()->GetRotationMatrix()
  << std::endl << std::endl;

  std::cout << "Translation vector: " << std::endl;
  std::cout <<=20
  =
m_Registrator->GetInternalRegistrationMethod()->GetMetric()->GetMapper()-=
>
   GetTransform()->GetOffset()
  << std::endl << std::endl;


Once you have M and t the relationship between points=20
in the *fixed/target* image and the *moving/reference* image is

(a - a_c) =3D M * ( b - b_c ) + t

where=20
b =3D point in the *fixed* image
b_c =3D is the center point of the *fixed/target* image
a =3D point in the *moving* image
a_c =3D is the center point of the *moving/reference* image
M =3D rotation matrix
t =3D translation

NOTE:=20
A point is different to an index.=20
Points take into spacing into account i.e.
  point[i] =3D spacing[i] * index[i]

Hope this helps.

BTW: have you resolve your previous issue
with setting the pixel type?

-Lydia
=20

> -----Original Message-----
> From: Buu Tien Phan [mailto:bphan@mail.uh.edu]
> Sent: Saturday, June 01, 2002 3:29 PM
> To: Lydia Ng
> Subject: Quaternion transformation
>=20
>=20
> Hello Lydia,
>=20
> Thank you for your explanation about the output. I am still not quite
> understanding. Correct me if I am wrong.
> Suppose I need to find the rotation parameters ( the angle=20
> and the axis) and
> the translation vector in MultiResMIRegistration example.
> >From the "Final parameters" line I have:
>=20
> "Final parameters: 0.000319651  8.89633e-005  0.0868807  0.996219
> 2.39833  -17.2735  -0.044853"
>=20
> - the fourth parameter is 0.996219. This means cos(t/2) =3D=20
> 0.996219, then I
> can find the rotation angle t. Am I right?  How do we know=20
> the rotation
> axis?
> - the last three parameters are about the translation. How do=20
> we compute the
> translation vector?
>=20
> Thank you very much for your help.
>=20
> Buu Phan
>=20
>=20
>=20
>=20
>=20
>=20