[Insight-users] Re: Re: AffineTransform

suresh suresh " <suresh_kb@rediffmail.com
17 Sep 2002 14:58:30 -0000


Hi Luis,

Thanks for your help.
I'm a little confused with the third point in your reply.
What i understood is ...
fixedImage=MRI, movingImage=SPECT and dont do any inverse in 
Transform.
This is my registration code.
/*******************
REGISTRATION CODE
*******************/

 	   typedef itk::AffineTransform<double> TransformType;
 	   typedef itk::RegularStepGradientDescentOptimizer 
OptimizerType;
 	   typedef itk::LinearInterpolateImageFunction <UCharImage, 
double> InterpolatorType;
 	   typedef itk::ImageRegistrationMethod <UCharImage , UCharImage 
 > RegistrationType;
 	   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();
 	   RegistrationType::Pointer  registration  = 
RegistrationType::New();

 	   
/******************************************************************
 	   * Set up the optimizer.
 	   
******************************************************************/

 	   // set the translation scale
 	   typedef OptimizerType::ScalesType ScalesType;
 	   ScalesType parametersScales( 
transform->GetNumberOfParameters() );

 	   parametersScales.Fill( 1.0 );

 	   for (int  j = 9; j < 12; j++ )
 	   {
 		   parametersScales[j] = 0.0001;
 	   }

 	   optimizer->SetScales( parametersScales );

 	   // need to maximize for mutual information
 	   optimizer->MaximizeOn();
 	   
/******************************************************************
 	   * Set up the metric.
        
******************************************************************/

 	   metric->SetMovingImageStandardDeviation( 5.0 );
 	   metric->SetFixedImageStandardDeviation( 5.0 );
 	   metric->SetNumberOfSpatialSamples( 50);
 	   metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() 
);


     
/******************************************************************
      * Set up the registrator.
      
******************************************************************/

 	 // connect up the components
 	  registration->SetMetric( metric );
 	  registration->SetOptimizer( optimizer );
 	  registration->SetTransform( transform );
 	  registration->SetFixedImage( MRI);
 	  registration->SetMovingImage(SPECT);
 	  registration->SetInterpolator( interpolator );

 	  // set initial parameters to identity
 	  RegistrationType::ParametersType initialParameters(
 					transform->GetNumberOfParameters() );

 	  initialParameters.Fill( 0.0 );
 	  initialParameters[0] = 1.0;
 	  initialParameters[4] = 1.0;
 	  initialParameters[8] = 1.0;

       registration->SetInitialTransformParameters( 
initialParameters );
       optimizer->SetNumberOfIterations(400);
 	  try
 	  {
 		  registration->StartRegistration();

 	  }catch(itk::ExceptionObject& Eo)
 	  {
 	     AfxMessageBox(Eo.GetDescription());
 		 return NULL;
 	  }
 	  // Get the results
 	  TransformType::MatrixType resultMatrix = 
transform->GetMatrix();
 	  TransformType::OffsetType resultVector = 
transform->GetOffset();

/**************************************************
The input to the transform is SPECT image.

TRANSFORM CODE
***************************************************/

 	typedef itk::ResampleImageFilter<UCharImage, UCharImage> 
ResampleFilter;
 	typedef ResampleFilter::TransformType  TransformType  ;
 	typedef UCharImage::SizeType  ImageSizeType;
 	typedef TransformType::MatrixType MatrixType;
 	typedef TransformType::OffsetType  VectorType;
 	ConverterType ::ImagePointer image = IGotTheImageSomeHow();

 	ImageSizeType size; // initialized this sizes with MRI size

 	ResampleFilter::Pointer resampleFilter = 
ResampleFilter::New();

 	TransformType::Pointer transform = 
resampleFilter->GetTransform();
 	VectorType vector = transform->GetOffset();
 	MatrixType matrix = transform->GetMatrix();
/************************************************************
 	Result is the double array in which i store the Martrix(0-8)
 	 and Vector(9-11)
**********************************/

 	matrix[0][0] = result[0]; matrix[0][1] = result[1] ; 
matrix[0][2] = result[2] ;
 	matrix[1][0] = result[3]; matrix[1][1] = result[4] ; 
matrix[1][2] = result[5] ;
 	matrix[2][0] = result[6]; matrix[2][1] = result[7] ; 
matrix[2][2] = result[8] ;

 	vector[0] = result[9]; vector[1] = result[10]; vector[2] = 
result[11];

 	transform->SetOffset(vector);
 	transform->SetMatrix(matrix);
 	UCharImage::Pointer outImage  = NULL;
 	resampleFilter ->SetTransform(transform);
         resampleFilter->SetInput(image);
 	try{
 		resampleFilter->Update();
 	}catch(itk::ExceptionObject &Eo){
 		AfxMessageBox(Eo.GetDescription());
 	}
 	outImage   = resampleFilter->GetOutput();

**********************************************/
But after applying transform the SPECT image did not GROW to the 
MRI size.

Your help with this is very much needed for me.

Thankyou,

-suresh