[Insight-users] AffineTransform
suresh
suresh " <suresh_kb@rediffmail.com
16 Sep 2002 10:16:52 -0000
Hi Luis,
Thanks a lot for help.It will be alot more helpful if you clarify
a few things on registration with AffineTransform
1. What about the transform parametres. I observed(by calling
transform->GetNumberOfParameters()) that there are 12 to be
given.What are they?
2. Is this peice of code still valid?
vnl_quaternion<double>
quat(solution[0],solution[1],solution[2],solution[3]);
vnl_matrix_fixed<double,3,3> vnlmat = quat.rotation_matrix();
3. I'm not going to swap the fixed and moving images(MRI, SPECT),
but while Transformation i'll get the Inverse matrix and apply.Is
that right?
This is modified code. for registration.
Matrix* mat = NULL;
double result[16];
typedef BufferToImageConversion<unsigned char>
ConverterType;
typedef ConverterType::ImageType UCharImage;
typedef itk::AffineTransform<double> TransformType;
typedef itk::RegularStepGradientDescentBaseOptimizer
OptimizerType;
typedef itk::LinearInterpolateImageFunction <UCharImage,
double> InterpolatorType;
typedef itk::ImageRegistrationMethod <UCharImage , UCharImage
> RegistrationType1;
typedef itk::MutualInformationImageToImageMetric<UCharImage ,
UCharImage> MetricType;
ProgressUpdate(50, "Performing MutualInformation
Registration", MRIVolumeName);
MetricType::Pointer metric =
MetricType::New();
TransformType::Pointer transform =
TransformType::New();
OptimizerType::Pointer optimizer =
OptimizerType::New();
InterpolatorType::Pointer interpolator =
InterpolatorType::New();
RegistrationType1::Pointer registration =
RegistrationType1::New();
ConverterType converter;
UCharImage::Pointer fixedImage = converter.GetImage(MRI);
UCharImage::Pointer movingImage =
converter.GetImage(SPECT);
RegistrationType1::ParametersType
guess(transform->GetNumberOfParameters() );
CString str;
str.Format(" Count %d",
transform->GetNumberOfParameters());
AfxMessageBox(str);
guess[0] = 0.0; guess[1] = 0.0; guess[2] = 0.0; guess[3] =
1.0;
guess[4] = 0.0; guess[5] = 0.0; guess[6] = 0.0; guess[7] =
0.0;
guess[8] = 0.0; guess[9] = 40.0; guess[10] = 20.0;
guess[11] = 0.0;
try{
registration->SetInitialTransformParameters (guess);
metric->SetMovingImageStandardDeviation( 2 );
metric->SetFixedImageStandardDeviation( 2 );
metric->SetNumberOfSpatialSamples( 1000 );
typedef OptimizerType::ScalesType ScaleType;
ScaleType scales(transform->GetNumberOfParameters());
scales.Fill( 1.0 );
for( unsigned j = 4; j < 12; j++ )
{
scales[j] = 1.0 / vnl_math_sqr(300.0);
}
//Scale parameters
optimizer->SetNumberOfIterations( 7 );
//set registration parameters
registration->SetMetric(metric);
registration->SetOptimizer(optimizer);
registration->SetTransform(transform);
registration->SetInterpolator(interpolator);
registration->SetFixedImage(movingImage);
registration->SetMovingImage(fixedImage);
registration->SetFixedImageRegion(
fixedImage->GetBufferedRegion() );
// Setup the optimizer
optimizer->SetScales(scales);
registration->DebugOn();
registration->StartRegistration();
ProgressUpdate(60, "Performing Normalized Registration15",
MRIVolumeName);
// Get the results
itk::Array<double> *arr=new itk::Array<double>;
RegistrationType1::ParametersType solution
=registration->GetLastTransformParameters();
vnl_quaternion<double>
quat(solution[0],solution[1],solution[2],solution[3]);
vnl_matrix_fixed<double,3,3> vnlmat =
quat.rotation_matrix();
result[0] = vnlmat[0][0]; result[1] = vnlmat[0][1];
result[2] = vnlmat[0][2]; result[3] = solution[4];
result[4] = vnlmat[1][0]; result[5] = vnlmat[1][1];
result[6] = vnlmat[1][2]; result[7] = solution[5];
result[8] = vnlmat[2][0]; result[9] = vnlmat[2][1];
result[10] = vnlmat[2][2]; result[11] = solution[6];
result[12] = 0; result[13] = 0; result[14] = 0; result[15] =
1;
With this code i could not go beyond the StartRegistration call?
Please help in fixing this..
And in Resample code i'm using the Inverse of Transform.
TransformType::Pointer inverseTransform =
transform->Inverse();
resampleFilter ->SetTransform(inverseTransform);
Thanks
suresh