[Insight-users] Problem with MeanSquaresImageToImageMetric.
Luis Ibanez
luis . ibanez at kitware . com
Mon, 26 Aug 2002 12:25:07 -0400
Hi Suresh,
It seems that you are missing to set up the "FixedImageRegion"
that is required by all metrics. This defines what region
of the Fixed image will participate in the computation of the
metric.
Typically the value is the "BufferedRegion()" but you can
set it to a region of a particular organ that you may be
more interested on.
The line should be like:
metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );
Also,
is this a typo in your email, or it this really in the code :
" catch(itk::Exception% Eo) " !!
it must be:
"catch( itk::ExceptionObject & Eo ) "
Please let us know if you still find any problem,
Thanks
Luis
=========================================================
suresh wrote:
> Hi Luis,
>
> Thanks for the help.
>
> Indeed, all that code i submitted was in a try-catch.
> It is not throwing any itk::Exception.
> Its throwing a windows runtime error.
>
> THIS PROGRAM HAS PERFORMED AN ILLEGALOPERATION AND WILL BE SHUTDOWN.
>
> ********Code snippet..1***
> typedef itk::QuaternionRigidTransform<double> TransformType;
> typedef itk::QuaternionRigidTransformGradientDescentOptimizer OptimizerType;
> typedef itk::LinearInterpolateImageFunction<ImageType, double> InterpolatorType;
> typedef itk::ImageRegistrationMethod<ImageType,ImageType> RegistrationType1;
>
> typedef itk::MeanSquaresImageToImageMetric<ImageType, ImageType> MetricType;
> 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();
> RegistrationType1::ParametersType guess(transform->GetNumberOfParameters() );
>
> guess[0] = 0.0; guess[1] = 0.0; guess[2] = 0.0; guess[3] = 1.0;
> guess[4] = 20.0; guess[5] = 40.0; guess[6] = 0.0;
>
> ImagePointer fixedImage = BufferToImage(MRI);// built from an pixel buffer
> ImagePointer movingImage = BufferToImage(SPECT);
>
> registration->SetInitialTransformParameters (guess);
> //Set translation scale
> typedef OptimizerType::ScalesType ScaleType;
> ScaleType scales(transform->GetNumberOfParameters());
> scales.Fill( 1.0 );
> for( unsigned j = 4; j < 7; j++ )
> {
> scales[j] = 1.0 / vnl_math_sqr(300.0);
> }
> //Scale parameters
> optimizer->SetNumberOfIterations( 1 );
> optimizer->SetLearningRate( 0.0000001 );
> //set registration parameters
> registration->SetMetric(metric);
> registration->SetOptimizer(optimizer);
> registration->SetTransform(transform);
> registration->SetInterpolator(interpolator);
> registration->SetFixedImage(fixedImage);
> registration->SetMovingImage(movingImage);
> // Setup the optimizer
> optimizer->SetScales(scales);
> try{
> registration->StartRegistration();
> }catch(itk::Exception% Eo){
> AfxMessageBox(Eo.GetDescription());
> }
> -----------------------------------------------------------------------
> I even tried to use the example code
>
> ****Code Snippet ...2*****
>
> typedef itk::AffineTransform< double, 3> TransformType;
> typedef TransformType::ParametersType ParametersType;
> typedef itk::GradientDescentOptimizer OptimizerType;
> typedef itk::MeanSquaresImageToImageMetric< ImageType, ImageType > MetricType;
> typedef itk:: LinearInterpolateImageFunction< ImageType, double >
> InterpolatorType;
> typedef itk::ImageRegistrationMethod<
> ImageType,
> ImageType > RegistrationType;
> typedef itk::CommandIterationUpdate <
> OptimizerType > CommandIterationType;
>
> MetricType::Pointer metric = MetricType::New();
> TransformType::Pointer transform = TransformType::New();
> OptimizerType::Pointer optimizer = OptimizerType::New();
> TransformType::Pointer trasform = TransformType::New();
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> RegistrationType::Pointer registration = RegistrationType::New();
> ImagePointer fixedImage = BufferToImage(MRI);
> ImagePointer movingImage = BufferToImage(SPECT);
> ImageType::RegionType region;
> ImageType::SizeType size;
> ImageType::IndexType index = ImageType::IndexType::ZeroIndex;
> size[0] = MRI->width;
> size[1] = MRI->height;
> size[2] = MRI->depth;
> region.SetSize( size );
> region.SetIndex( index );
> movingImage->SetLargestPossibleRegion( region );
> movingImage->SetBufferedRegion( region );
> movingImage->SetRequestedRegion( region );
> movingImage->Allocate();
> fixedImage->SetLargestPossibleRegion( region );
> fixedImage->SetBufferedRegion( region );
> fixedImage->SetRequestedRegion( region );
> fixedImage->Allocate();
> registration->SetMetric( metric );
> registration->SetOptimizer( optimizer );
> registration->SetTransform( transform );
> registration->SetFixedImage( fixedImage );
> registration->SetMovingImage( movingImage );
> registration->SetInterpolator( interpolator );
> metric->SetFixedImageRegion( fixedImage->GetBufferedRegion() );
> CommandIterationType::Pointer iterationCommand = CommandIterationType::New();
> iterationCommand->SetOptimizer( optimizer.GetPointer() );
> OptimizerType::ScalesType scales( transform->GetNumberOfParameters() );
> scales.Fill( 1.0 );
> unsigned long numberOfIterations = 10;
> double translationScale = 1e-4;
> double learningRate = 1e-6;
> for( unsigned int i=0; i<Dimension; i++)
> {
> scales[ i + Dimension * Dimension] = translationScale;
> }
>
> optimizer->SetScales( scales );
> optimizer->SetLearningRate( learningRate );
> optimizer->SetNumberOfIterations( numberOfIterations );
> optimizer->MinimizeOn();
> transform->SetIdentity();
> registration->SetInitialTransformParameters( transform->GetParameters() );
> try
> {
> registration->StartRegistration();
> }
> catch( itk::ExceptionObject & e )
> {
> AfxMessageBox(e.GetDescription());
> }
> ---------------------------------------------------------------------------
>
> As I wrote earlier The BufferToImage Function builds an Image from a Buffer.
> The code sniuppet .. 1 works perfectly with itk::MutualInformationImageToImageMetric.
>
> I could not identify whats wrong with MeanSquaresImageToImageMetric.
> Is there any thing that i need to initialize with, fixedImage and movingImages??
>
> please help me with this.
>
> Thanks,
>
> suresh
>
>
>
>
>
>
>
>