[Insight-users] OnePlusOne Optimizer - results are always 0
itkvtk123 at gmx.net
itkvtk123 at gmx.net
Wed Sep 9 08:06:27 EDT 2009
Hi!
I'm trying to register two 2d images using the OnePlusOne optimizer (global optimization).
I wanted to give it a try because gradient descent got stuck in local minima all the time.
However, the result of the OnePlusOne is always Rotation=0, TranslationX=0, TranslationY=0.
(Same during entire process -> I monitored it using the observer).
I'm using the NormalizedCorrelationMetric.
Am I doing something wrong or is something missing? (see code)
Take also a look at
http://img3.imageshack.us/img3/1552/unbenannttnb.jpg
for a screenshot of my program (lower left = image 1, lower right = image 2, upper left = subtraction image after registration).
Source:
const Image2DType::Pointer ImageRegistration::registerImagesXYR(const Image2DType::Pointer fixedImage, const Image2DType::Pointer movingImage)
{
typedef itk::CenteredRigid2DTransform<double> RigidTransformType;
typedef itk::CenteredTransformInitializer<RigidTransformType, Image2DType, Image2DType> TransformInitializerType;
typedef itk::NormalizedCorrelationImageToImageMetric<Image2DType, Image2DType> MetricType;
typedef itk::OnePlusOneEvolutionaryOptimizer OptimizerType;
typedef itk::Statistics::NormalVariateGenerator GeneratorType;
typedef itk::LinearInterpolateImageFunction<Image2DType, double> InterpolatorType;
typedef itk::ImageRegistrationMethod<Image2DType, Image2DType> RegistrationType;
//initialize needed objects
MetricType::Pointer metric = MetricType::New();
RigidTransformType::Pointer transform = RigidTransformType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
InterpolatorType::Pointer interpolator = InterpolatorType::New();
RegistrationType::Pointer registration = RegistrationType::New();
//connect objects to registration
registration->SetMetric(metric);
registration->SetOptimizer(optimizer);
registration->SetTransform(transform);
registration->SetInterpolator(interpolator);
TransformInitializerType::Pointer initializer = TransformInitializerType::New();
initializer->SetTransform(transform);
initializer->SetFixedImage(fixedImage);
initializer->SetMovingImage(movingImage);
initializer->GeometryOn();
initializer->InitializeTransform();
transform->SetAngle(0.0);
registration->SetInitialTransformParameters(transform->GetParameters());
//we want to register movingImage against fixedImage
registration->SetFixedImage(fixedImage);
registration->SetMovingImage(movingImage);
//we want to register the entire image
registration->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());
//now registration is ready
typedef OptimizerType::ScalesType OptimizerScalesType;
OptimizerScalesType optimizerScales(transform->GetNumberOfParameters());
const Image2DType::SpacingType fixedSpacing = fixedImage->GetSpacing();
const Image2DType::SizeType fixedSize = fixedImage->GetLargestPossibleRegion().GetSize();
const double translationScale = 1.0 / (fixedSize[0] * fixedSpacing[0] * sqrt(2.0));
optimizerScales[0] = 1.0;
optimizerScales[1] = translationScale;
optimizerScales[2] = translationScale;
optimizerScales[3] = translationScale;
optimizerScales[4] = translationScale;
optimizer->SetScales(optimizerScales);
GeneratorType::Pointer generator = GeneratorType::New();
generator->Initialize(12345);
optimizer->MaximizeOff();
optimizer->SetNormalVariateGenerator(generator);
optimizer->Initialize(10);
optimizer->SetEpsilon(1.0);
optimizer->SetMaximumIteration(400); //4000
//add observer pattern to monitor evolution of optimization / registration process
CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
optimizer->AddObserver(itk::IterationEvent(), observer);
try
{
registration->StartRegistration();
}
catch(itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
exit(EXIT_FAILURE);
}
// get the registration parameters
typedef RegistrationType::ParametersType ParametersType;
ParametersType finalParameters = registration->GetLastTransformParameters();
std::cout << -finalParameters[0] * 180.0 / vnl_math::pi << " " << finalParameters[3] << finalParameters[4] << std::endl;
//final Output: 0 0 0 (same during entire process)
}
Thank you.
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
More information about the Insight-users
mailing list