[Insight-users] Mattes Mutual Information "Too many samples map outside moving image buffer"

Marta t_s_80 at gmx.de
Wed Jan 7 05:54:47 EST 2009


Hi,

I'm using Mattes Mutual Information for registration and it is working  
fine if I use the whole image (tried it with the images  
BrainT1SliceBorder20.png and BrainProtonDensitySliceRotated10.png).  
But what I want to do, is to register just a part of the moving image,  
like in the following example (I hope you can see it) the fixed image  
with the moving image part B:

-------------------------------                
-------------------------------
|                                       |                 
|                                      |	
|                                       |                |        
movingImage      | 	
|          fixedImage	        |                |         
---------                  |
|                                       |                |        |    
B    |                  |
|                                       |                |         
|          |                  |
|                                       |                |         
---------                  |
-------------------------------                 
------------------------------

If I'm doing so i get the following error:

itk::ExceptionObject (0x16693070)
Location: "void  
itk::MattesMutualInformationImageToImageMetric<TFixedImage,  
TMovingImage>::GetValueAndDerivative(const typename  
itk::ImageToImageMetric<TFixedImage, TMovingImage>::ParametersType&,  
typename itk::ImageToImageMetric<TFixedImage,  
TMovingImage>::MeasureType&, typename  
itk::ImageToImageMetric<TFixedImage, TMovingImage>::DerivativeType&)  
const [with TFixedImage = itk::Image<unsigned char, 2u>, TMovingImage  
= itk::Image<unsigned char, 2u>]"
File: /Users/tine/InsightToolkit-3.10.1/Code/Algorithms/ 
itkMattesMutualInformationImageToImageMetric.txx
Line: 1110
Description: itk::ERROR:  
MattesMutualInformationImageToImageMetric(0x1951ec10): Too many  
samples map outside moving image buffer: 1233 / 5000

I assume, that the samples are taken from the fixed image and the  
moving image is too small than!? If so, what can I do to solve the  
problem? I tried it also with more samples, but it didn't work as well.

The crucial code I'm using is the following:


------------------------------------------------- Code  
------------------------------------------------------------------

	//typedefs in the header
	CenteredRigid2DTransformType::Pointer transform =  
CenteredRigid2DTransformType::New( );
	OptimizerType::Pointer      optimizer     = OptimizerType::New();
	InterpolatorType::Pointer   interpolator  = InterpolatorType::New();
	RegistrationType::Pointer   registration  = RegistrationType::New();
	MattesMutualInformationMetricType::Pointer metric =  
MattesMutualInformationMetricType::New();

	registration->SetOptimizer( optimizer );
	registration->SetTransform( transform );
	registration->SetInterpolator( interpolator );
	registration->SetMetric( metric );

	unsigned int numberOfBins = 24;
	unsigned int numberOfSamples = 5000;

	metric->SetNumberOfHistogramBins( numberOfBins );
	metric->SetNumberOfSpatialSamples( numberOfSamples );

	ImageType::Pointer movingImage = ImageType::New( );
	ImageType::Pointer fixedImage = ImageType::New( );

	/* use member variables for the images */
	//whole image
	fixedImage = image->getItkImage( );
	//just an image part
	movingImage = m_itkImage;
		
	registration->SetFixedImage( fixedImage );
	registration->SetMovingImage( movingImage );
		
	registration->SetFixedImageRegion( fixedImage->GetBufferedRegion( ) );
		
	//  Compute the xenter of rotation with the origin, size and spacing  
of the fixed image.
	const SpacingType fixedSpacing = fixedImage->GetSpacing( );
	const PointType fixedOrigin = fixedImage->GetOrigin( );
	const RegionType fixedRegion = fixedImage->GetLargestPossibleRegion( );
	const SizeType fixedSize = fixedRegion.GetSize( );
		
	CenteredRigid2DTransformType::InputPointType centerFixed;
		
	centerFixed[0] = fixedOrigin[0] + fixedSpacing[0] * fixedSize[0] / 2.0;
	centerFixed[1] = fixedOrigin[1] + fixedSpacing[1] * fixedSize[1] / 2.0;
		
	CenteredRigid2DTransformType::InputPointType centerMoving;

	//compute center of the moving image		
	const SpacingType movingSpacing = movingImage->GetSpacing( );
	const PointType  movingOrigin  = movingImage->GetOrigin( );
	const RegionType  movingRegion  = movingImage- 
 >GetLargestPossibleRegion( );
	const SizeType    movingSize    = movingRegion.GetSize( );
		
	centerMoving[ 0 ] = movingOrigin[ 0 ] + movingSpacing[ 0 ] *  
movingSize[ 0 ] / 2.0;
	centerMoving[ 1 ] = movingOrigin[ 1 ] + movingSpacing[ 1 ] *  
movingSize[ 1 ] / 2.0;
		
		
	//set rotation center and translation vector. Registration should  
start with the image part on the same position, how it was before.
	transform->SetCenter( centerMoving );
	transform->SetTranslation( 0.0 );
		
	//initialize rotation with zero angle.
	transform->SetAngle( 0.0 );		
		
	registration->SetInitialTransformParameters( transform- 
 >GetParameters( ) );
		
	typedef OptimizerType::ScalesType       OptimizerScalesType;
	OptimizerScalesType optimizerScales( transform- 
 >GetNumberOfParameters() );
	const double translationScale = 1.0 / 1000.0;
		
	optimizerScales[0] = 1.0;
	optimizerScales[1] = translationScale;
	optimizerScales[2] = translationScale;
	optimizerScales[3] = translationScale;
	optimizerScales[4] = translationScale;
		
	optimizer->SetScales( optimizerScales );
		
	optimizer->MinimizeOn( );
	optimizer->SetMaximumStepLength( 1.0 );
	optimizer->SetMinimumStepLength( 0.001 );
	optimizer->SetNumberOfIterations( m_NumIterations );

	optimizer->SetRelaxationFactor( 0.8 );

	CommandIterationUpdate::Pointer observer =  
CommandIterationUpdate::New();
	optimizer->AddObserver( itk::IterationEvent(), observer );
	
try {
		registration->Update( );
	}
	catch( itk::ExceptionObject & err )
	{
		std::cerr << "ExceptionObject caught !" << std::endl;
		std::cerr << err << std::endl;
	}

------------------------------------------------- Code end  
------------------------------------------------------------------

Any suggestions what I can do to avoid the upper error?

Thanks a lot for your help!

Best regards,
Marta


More information about the Insight-users mailing list