[Insight-users] Inverse transform problem of given parameters
Fucang Jia
jiafucang at asisz.com
Thu Oct 27 23:03:15 EDT 2005
Hi, everyone,
I want to use inverse transform of ITK registration result recently. So I want to use the convenient GetInverse method to get the inverse transform. When I give the transform parameters,
the GetInverse seems not occurs, which is at line 260th in itkMatrixOffsetTransformBase.txx version 1.10:
if(m_InverseMatrixMTime != m_MatrixMTime)
Should I add some code to enforce it compute? Thank you very much!
Fucang
=============================================================
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include <iostream>
#include "itkMatrix.h"
#include "itkAffineTransform.h"
int main(int argc, char *argv[] )
{
double transformmatrix[12];
transformmatrix[0] = 0.999797;
transformmatrix[1] = -0.00583563;
transformmatrix[2] = -0.0192842l;
transformmatrix[3] = 0.00591944;
transformmatrix[4] = 0.999973;
transformmatrix[5] = 0.00429143;
transformmatrix[6] = 0.0192587;
transformmatrix[7] = -0.00440471;
transformmatrix[8] = 0.999805;
transformmatrix[9] = -0.690118;
transformmatrix[10] = -0.823229;
transformmatrix[11] = -15.285;
// matrix inverse method
typedef double NumericType;
typedef itk::Matrix<NumericType,4,4> MatrixType;
MatrixType matrix;
matrix.Fill( 0.0 );
matrix[0][0] = transformmatrix[0];
matrix[0][1] = transformmatrix[1];
matrix[0][2] = transformmatrix[2];
matrix[1][0] = transformmatrix[3];
matrix[1][1] = transformmatrix[4];
matrix[1][2] = transformmatrix[5];
matrix[2][0] = transformmatrix[6];
matrix[2][1] = transformmatrix[7];
matrix[2][2] = transformmatrix[8];
matrix[0][3] = transformmatrix[9];
matrix[1][3] = transformmatrix[10];
matrix[2][3] = transformmatrix[11];
matrix[3][3] = 1.0;
vnl_matrix_fixed<double,4,4> invmatrix = matrix.GetInverse();
std::cout<<"vnl inverse method: "<<std::endl;
std::cout<<invmatrix<<std::endl;
// affine transform inverse method
typedef itk::AffineTransform<double, 3> AffineTransformType;
AffineTransformType::Pointer paff = AffineTransformType::New();
AffineTransformType::Pointer inv = AffineTransformType::New();
AffineTransformType::ParametersType parameters(paff->GetNumberOfParameters());
for(int i=0;i<12;i++)
parameters[i] = transformmatrix[i];
paff->SetParameters(parameters);
paff->GetInverse(inv);
inv->Print(std::cout);
std::cout<<"affine transform inverse method: "<<std::endl;
std::cout<<inv->GetParameters()<<std::endl;
return 0;
}
The experiment is as follows:
vnl inverse method:
0.999797 0.00591943 0.0192586 0.989219
-0.00583564 0.999974 -0.00440471 0.751854
-0.0192843 0.00429143 0.999805 15.2722
-2.60209e-018 -2.86229e-017 4.16334e-017 1
AffineTransform (00372CF0)
RTTI typeinfo: class itk::AffineTransform<double,3>
Reference Count: 1
Modified Time: 3
Debug: Off
Observers:
none
Matrix:
1 0 0
0 1 0
0 0 1
Offset: [0.690118, 0.823229, 15.285]
Center: [0, 0, 0]
Translation: [0.690118, 0.823229, 15.285]
Inverse:
0.999797 -0.00583563 -0.0192842
0.00591944 0.999973 0.00429143
0.0192587 -0.00440471 0.999805
Singular: 0
affine transform inverse method:
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0.690118, 0.823229, 15.285]
More information about the Insight-users
mailing list