[Insight-users] Registration binary images
Serena Fabbri
fabbri at u.washington.edu
Fri Oct 16 21:17:10 EDT 2009
Hi All,
I am registering binary images with
Affine Transformation, MatchCardinality Metric, Amoeba optimizer, NearestNeighbor Interpolator.
When I set optimizerScales with SetScales( optimizerScales ), I obtain this message independently by
chosen values.
ExceptionObject caught !
itk::ExceptionObject (0x66d6a0)
Location: "typename itk::MatchCardinalityImageToImageMetric<TFixedImage,
TMovingImage>::MeasureType itk::MatchCardinalityImageToImageMetric<TFixedImage,
TMovingImage>::GetNonconstValue(const typename itk::ImageToImageMetric<TFixedImage,
TMovingImage>::TransformParametersType&) [with TFixedImage = main(int, char**)::FixedImageType,
TMovingImage = main(int, char**)::MovingImageType]"
File: /Users/physics/InsightToolkit-
3.10.0/Code/Algorithms/itkMatchCardinalityImageToImageMetric.txx
Line: 130
Description: itk::ERROR: MatchCardinalityImageToImageMetric(0x6690c0): All the points mapped to
outside of the moving image
If I don't set optimizerScales the registration starts but I have another problem.
I visualize the registration task with an observer with these 2 instruction:
std::cout << optimizer->GetCachedCurrentPosition()<< " ";
std::cout << optimizer->GetCachedValue() ;
and it seems work but when I call
OptimizerType::ParametersType finalParameters = registration->GetLastTransformParameters();
I get the initial parameters, so the output image is not registered.
does anyone experience with Affine Registration of binary image?
Could you give me any suggestion?
Thank you for any advice.
Serena.
this is the code:
// Metric
metric->MeasureMatchesOff();
// Transform
TransformInitializerType::Pointer initializer = TransformInitializerType::New();
initializer->SetTransform( transform );
initializer->SetFixedImage( fixedImageReader->GetOutput() );
initializer->SetMovingImage( movingImageReader->GetOutput() );
initializer->GeometryOn();
initializer->InitializeTransform();
//Optimizer
unsigned int maxNumberOfIterations = 2000;
if( argc > 3 )
{
maxNumberOfIterations = atoi( argv[4] );
}
OptimizerType::ParametersType
simplexDelta( transform->GetNumberOfParameters() );
simplexDelta.Fill( 10.0 );
std::cout<<"simplexDelta "<<simplexDelta<<std::endl;
std::cout<<"GetScales() "<<optimizer->GetScales()<<std::endl;
typedef OptimizerType::ScalesType OptimizerScalesType;
OptimizerScalesType optimizerScales( transform->GetNumberOfParameters() );
optimizerScales[0] = 1.000;
optimizerScales[1] = 1.000;
optimizerScales[2] = 1.000;
optimizerScales[3] = 1.000;
optimizerScales[4] = 1.000;
optimizerScales[5] = 1.000;
optimizerScales[6] = 1.000;
optimizerScales[7] = 1.000;
optimizerScales[8] = 1.000;
double translationScale = 1.000;
optimizerScales[9] = translationScale;
optimizerScales[10] = translationScale;
optimizerScales[11] = translationScale;
optimizer->SetScales( optimizerScales );
std::cout<<"GetScales() "<<optimizer->GetScales()<<std::endl;
optimizer->AutomaticInitialSimplexOff();
optimizer->SetInitialSimplexDelta( simplexDelta );
optimizer->SetParametersConvergenceTolerance( 0.25 ); // quarter pixel
optimizer->SetFunctionConvergenceTolerance(0.1); // 0.1%
optimizer->SetMaximumNumberOfIterations(maxNumberOfIterations );
//Registration
registration->SetMetric( metric );
registration->SetOptimizer( optimizer );
registration->SetInterpolator( interpolator );
registration->SetTransform( transform );
registration->SetFixedImage( fixedImageReader->GetOutput() );
registration->SetMovingImage( movingImageReader->GetOutput() );
registration->SetFixedImageRegion( fixedImageReader->GetOutput()-
>GetBufferedRegion() );
registration->SetInitialTransformParameters( transform->GetParameters() );
// Osservatori
itkProbesCreate();
CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
optimizer->AddObserver( itk::IterationEvent(), observer);
std::cout << std::endl << "Starting Affine Registration " << std::endl;
std::cout << transform->GetNumberOfParameters()<< " " << transform-
>GetParameters()<<std::endl;
try
{
registration->Initialize();
std::cout << "Initial Metric value = "<< metric->GetValue(transform-
>GetNumberOfParameters() ) << std::endl;
itkProbesStart( "Affine Registration " );
registration->StartRegistration();
itkProbesStop( "Affine Registration " );
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
// Report the time and memory taken by the registration
itkProbesReport( std::cout );
std::cout << "Affine Registration completed" << std::endl;
std::cout << std::endl;
OptimizerType::ParametersType finalParameters =
registration->GetLastTransformParameters();
const double finalRotationCenterX = transform->GetCenter()[0];
const double finalRotationCenterY = transform->GetCenter()[1];
const double finalRotationCenterZ = transform->GetCenter()[2];
const double finalTranslationX = finalParameters[9];
const double finalTranslationY = finalParameters[10];
const double finalTranslationZ = finalParameters[11];
const unsigned int numberOfIterations = optimizer->GetOptimizer()->get_num_evaluations();
const double bestValue = optimizer->GetValue();
// Print out results
std::cout << "Result = " << std::endl;
std::cout << " Center X = " << finalRotationCenterX << std::endl;
std::cout << " Center Y = " << finalRotationCenterY << std::endl;
std::cout << " Center Z = " << finalRotationCenterZ << std::endl;
std::cout << " Translation X = " << finalTranslationX << std::endl;
std::cout << " Translation Y = " << finalTranslationY << std::endl;
std::cout << " Translation Z = " << finalTranslationZ << std::endl;
std::cout << " Iterations = " << numberOfIterations << std::endl;
std::cout << " Metric value = " << bestValue << std::endl;
std::cout << " finalParameters = "<<finalParameters<<std::endl;
std::cout << " finalParameters = "<<transform->GetParameters()<<std::endl;
//write time
TransformType::Pointer finalTransform = TransformType::New();
finalTransform->SetCenter( transform->GetCenter() );
finalTransform->SetParameters( finalParameters );
resampler->SetTransform( finalTransform );
resampler->SetInput( movingImageReader->GetOutput() );
FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
resampler->SetOutputOrigin( fixedImage->GetOrigin() );
resampler->SetOutputSpacing( fixedImage->GetSpacing() );
resampler->SetOutputDirection( fixedImage->GetDirection() );
resampler->SetDefaultPixelValue( 0 );
writer->SetFileName( argv[3] );
caster->SetInput( resampler->GetOutput() );
writer->SetInput( caster->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
More information about the Insight-users
mailing list