[prev in list] [next in list] [prev in thread] [next in thread]
List: insight-users
Subject: Re: [Insight-users] Going from 4x4 matrix to Similarity3DTransform
From: Jan Owoc <jsowoc () gmail ! com>
Date: 2006-01-28 19:53:10
Message-ID: 35b78e360601281153k2c625e45t () mail ! gmail ! com
[Download RAW message or body]
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@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
>
[Attachment #3 (text/html)]
Thank you Luis,<br>
<br>
I am getting answers, but something is not right. My code is as follows:<br>
<br>
(...)<br>
int i = 0;<br>
int j = 0;<br>
vnl_matrix<double> m(3,3);<br>
<br>
cout << "Enter the 3x3 rotation/scale matrix, across first." \
<< endl;<br> for (i = 0; i < 3; i++)<br>
for (j = 0; j < 3; j++)<br>
cin >> m[i][j];<br>
vnl_svd<double> svd(m);<br>
vnl_matrix<double> r(3,3);<br>
r = svd.U() * vnl_transpose(svd.V());<br>
<br>
typedef itk::Similarity3DTransform< double > TransformType;<br>
typedef TransformType::VersorType VersorType;<br>
VersorType myrot;<br>
typedef VersorType::MatrixType MatrixType;<br>
MatrixType mat;<br>
for (i = 0; i < 3; i++)<br>
for (j = 0; j < 3; j++)<br>
mat[i][j] = r[i][j];<br>
myrot.Set(mat);<br>
<br>
cout << "Scale factor:\t" << myrot.GetScalar() << \
endl;<br> cout << "X versor:\t" << myrot.GetX() << \
endl;<br> cout << "Y versor:\t" << myrot.GetY() << \
endl;<br> cout << "Z versor:\t" << myrot.GetZ() << \
endl;<br> (...)<br>
<br>
In a different program, I have:<br>
(...)<br>
typedef itk::Similarity3DTransform<double> TransformType;<br>
TransformType::Pointer transform = TransformType::New();<br>
(...) set parameters, perform registration (...)<br>
const itk::Matrix<double,3,3> matrix3x3 = transform->GetMatrix();<br>
cout << " - 3x3 transform matrix:" << endl;<br>
for (int i = 0; i < 3; i++) {<br>
cout << " ";<br>
for (int j = 0; j < 3; j++) {<br>
printf("%8.4f ",matrix3x3[i][j]);<br>
}<br>
cout << endl;<br>
}<br>
(...)<br><br>
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?<br>
<br>
Thank you for your help.<br>
<br>
Jan Owoc<br>
<br>
<br><div><span class="gmail_quote">2006/1/24, Luis Ibanez <<a \
href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>>:</span><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> <br><br>Hi Jan,<br><br><br>In order to convert your \
4x4 transform in to an<br>ITK Similarity transform you can do the \
following<br><br><br>Your 4x4 matrix can be interpreted \
as:<br><br> R11 R12 R13 \
T1<br> R21 R22 R23 T2
<br> R31 R32 R33 \
T3<br> Sh1 Sh2 Sh3 SC<br><br><br>Where<br><br> \
T1,T2,T3 are \
Translations<br> \
SC is a \
Scalinig factor<br> Sh1,Sh2,Sh3 are \
Shearing factors<br> R11... R33 are \
the rotations <br><br><br>If your 4x4 matrix is formed correctly<br>representing a \
Similarit transform, then<br>the following constrains may be maintained<br><br><br>1) \
Sh1, Sh2, Sh3 MUST be null<br>2) The 3x3 submatrix \
R11..R22 MUST be orthogonal <br><br><br><br>It that holds true, then you \
can use SVD in order<br>to find the Versor that matches the 3x3 matrix.<br><br>You \
will find and example on how to do this on<br>the Registration \
example:<br><br> Insight/ \
<br> \
Examples/<br> \
Registration/<br>
ImageRegistration9.cxx<br><br><br>Then you can setup the ITK Similarity \
transform<br>by using:<br><br><br> A) an ITK \
Versor for the rotation<br> B) an ITK Vector for \
the translation<br> C) a scalar value for the \
Scaling <br><br><br><br>Please let us know if you have further \
questions.<br><br><br><br> Thanks<br><br><br> Luis<br>
</blockquote></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic