[Insight-users] Going from 4x4 matrix to Similarity3DTransform and back during registration

Jan Owoc jsowoc at gmail.com
Sat Jan 28 14:53:10 EST 2006


Thank you Luis,

I am getting answers, but something is not right. My code is as follows:

(...)
  int i = 0;
  int j = 0;
  vnl_matrix<double> m(3,3);

  cout << "Enter the 3x3 rotation/scale matrix, across first." << endl;
  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++)
      cin >> m[i][j];
  vnl_svd<double> svd(m);
  vnl_matrix<double> r(3,3);
  r = svd.U() * vnl_transpose(svd.V());

  typedef itk::Similarity3DTransform< double > TransformType;
  typedef TransformType::VersorType VersorType;
  VersorType myrot;
  typedef VersorType::MatrixType MatrixType;
  MatrixType mat;
  for (i = 0; i < 3; i++)
    for (j = 0; j < 3; j++)
      mat[i][j] = r[i][j];
  myrot.Set(mat);

  cout << "Scale factor:\t" << myrot.GetScalar() << endl;
  cout << "X versor:\t" << myrot.GetX() << endl;
  cout << "Y versor:\t" << myrot.GetY() << endl;
  cout << "Z versor:\t" << myrot.GetZ() << endl;
(...)

In a different program, I have:
(...)
  typedef itk::Similarity3DTransform<double> TransformType;
  TransformType::Pointer transform = TransformType::New();
(...) set parameters, perform registration (...)
  const itk::Matrix<double,3,3> matrix3x3 = transform->GetMatrix();
  cout << "  - 3x3 transform matrix:" << endl;
  for (int i = 0; i < 3; i++) {
    cout << "      ";
    for (int j = 0; j < 3; j++) {
      printf("%8.4f ",matrix3x3[i][j]);
    }
    cout << endl;
  }
(...)

When I take the 3x3 transform matrix, and put in in the SVD program, I don't
get my original 3 versors and scale. What am I doing wrong?

Thank you for your help.

Jan Owoc


2006/1/24, Luis Ibanez <luis.ibanez at kitware.com>:
>
>
>
> Hi Jan,
>
>
> In order to convert your 4x4 transform in to an
> ITK Similarity transform you can do the following
>
>
> Your 4x4 matrix can be interpreted as:
>
>       R11  R12  R13  T1
>       R21  R22  R23  T2
>       R31  R32  R33  T3
>       Sh1  Sh2  Sh3  SC
>
>
> Where
>
>      T1,T2,T3       are Translations
>      SC             is a Scalinig factor
>      Sh1,Sh2,Sh3    are Shearing factors
>      R11... R33     are the rotations
>
>
> If your 4x4 matrix is formed correctly
> representing a Similarit transform, then
> the following constrains may be maintained
>
>
> 1) Sh1, Sh2, Sh3  MUST be null
> 2) The 3x3 submatrix R11..R22  MUST be orthogonal
>
>
>
> It that holds true, then you can use SVD in order
> to find the Versor that matches the 3x3 matrix.
>
> You will find and example on how to do this on
> the Registration example:
>
>       Insight/
>            Examples/
>                Registration/
>                    ImageRegistration9.cxx
>
>
> Then you can setup the ITK Similarity transform
> by using:
>
>
>        A) an ITK Versor for the rotation
>        B) an ITK Vector for the translation
>        C) a scalar value for the Scaling
>
>
>
> Please let us know if you have further questions.
>
>
>
>       Thanks
>
>
>         Luis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060128/8d06cbff/attachment.htm


More information about the Insight-users mailing list