[Insight-users] OnePlusOne Optimizer - results are always 0
Luis Ibanez
luis.ibanez at kitware.com
Wed Sep 9 08:50:18 EDT 2009
Hi itkvtk123,
The iteration reporting of the OnePlusOneOptimizer
tends to be misleading because it reports the "best"
value found so far.
As you probably know, this optimizer works by generating
random positions around the last "best position", at every
iteration it tries a group of new positions, and if none of them
returns a better value, then the "best value so far" is still
reported in the output.
So, it is normal for this optimizer to report for several iterations
(sometimes hundreds) the same metric value (and position
value), and then switch to another value when a better metric
value is found.
In general, if you see the same value for a long time, it
means that you are not setting the optimizer to explore
values in a large enough region. That is, it may be
constrained to a small region.
Two things are strange in your report:
1) You say that you see always values of zeros in the
transform parameters, but at the same time you
are using the Transform initializer.
Can you verify that the First transform (the one computed
by the initializer) also has values of zeros in its parameters ?
2) You are setting a value of Epsilon = 1.0, which may be
too small for generating parameters variations that will
move you more than one pixel away.
You may want to try with larger Epsilon values (in the order
of 10.0 or larger).
Luis
------------------------------------------------------
On Wed, Sep 9, 2009 at 8:06 AM, <itkvtk123 at gmx.net> wrote:
> 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
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090909/3329c907/attachment-0001.htm>
More information about the Insight-users
mailing list