<br>Hi <span dir="ltr">itkvtk123</span>,<br><br>The iteration reporting of the OnePlusOneOptimizer<br>tends to be misleading because it reports the "best"<br>value found so far. <br><br>As you probably know, this optimizer works by generating<br>
random positions around the last "best position", at every<br>iteration it tries a group of new positions, and if none of them<br>returns a better value, then the "best value so far" is still<br>reported in the output.<br>
<br>So, it is normal for this optimizer to report for several iterations<br>(sometimes hundreds) the same metric value (and position <br>value), and then switch to another value when a better metric <br>value is found.<br>
<br>In general, if you see the same value for a long time, it<br>means that you are not setting the optimizer to explore<br>values in a large enough region. That is, it may be <br>constrained to a small region.<br><br><br>
Two things are strange in your report:<br><br>1) You say that you see always values of zeros in the <br> transform parameters, but at the same time you <br> are using the Transform initializer.<br> <br> Can you verify that the First transform (the one computed<br>
by the initializer) also has values of zeros in its parameters ?<br><br>2) You are setting a value of Epsilon = 1.0, which may be<br> too small for generating parameters variations that will<br> move you more than one pixel away.<br>
<br> You may want to try with larger Epsilon values (in the order<br> of 10.0 or larger).<br><br><br><br> Luis<br><br><br><br>------------------------------------------------------<br><div class="gmail_quote">On Wed, Sep 9, 2009 at 8:06 AM, <span dir="ltr"><<a href="mailto:itkvtk123@gmx.net">itkvtk123@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi!<br>
<br>
I'm trying to register two 2d images using the OnePlusOne optimizer (global optimization).<br>
I wanted to give it a try because gradient descent got stuck in local minima all the time.<br>
<br>
However, the result of the OnePlusOne is always Rotation=0, TranslationX=0, TranslationY=0.<br>
(Same during entire process -> I monitored it using the observer).<br>
<br>
I'm using the NormalizedCorrelationMetric.<br>
Am I doing something wrong or is something missing? (see code)<br>
<br>
Take also a look at<br>
<br>
<a href="http://img3.imageshack.us/img3/1552/unbenannttnb.jpg" target="_blank">http://img3.imageshack.us/img3/1552/unbenannttnb.jpg</a><br>
<br>
for a screenshot of my program (lower left = image 1, lower right = image 2, upper left = subtraction image after registration).<br>
<br>
Source:<br>
<br>
const Image2DType::Pointer ImageRegistration::registerImagesXYR(const Image2DType::Pointer fixedImage, const Image2DType::Pointer movingImage)<br>
{<br>
typedef itk::CenteredRigid2DTransform<double> RigidTransformType;<br>
typedef itk::CenteredTransformInitializer<RigidTransformType, Image2DType, Image2DType> TransformInitializerType;<br>
typedef itk::NormalizedCorrelationImageToImageMetric<Image2DType, Image2DType> MetricType;<br>
typedef itk::OnePlusOneEvolutionaryOptimizer OptimizerType;<br>
typedef itk::Statistics::NormalVariateGenerator GeneratorType;<br>
typedef itk::LinearInterpolateImageFunction<Image2DType, double> InterpolatorType;<br>
typedef itk::ImageRegistrationMethod<Image2DType, Image2DType> RegistrationType;<br>
<br>
<br>
<br>
//initialize needed objects<br>
MetricType::Pointer metric = MetricType::New();<br>
RigidTransformType::Pointer transform = RigidTransformType::New();<br>
OptimizerType::Pointer optimizer = OptimizerType::New();<br>
InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
RegistrationType::Pointer registration = RegistrationType::New();<br>
<br>
//connect objects to registration<br>
registration->SetMetric(metric);<br>
registration->SetOptimizer(optimizer);<br>
registration->SetTransform(transform);<br>
registration->SetInterpolator(interpolator);<br>
<br>
TransformInitializerType::Pointer initializer = TransformInitializerType::New();<br>
<br>
initializer->SetTransform(transform);<br>
<br>
initializer->SetFixedImage(fixedImage);<br>
initializer->SetMovingImage(movingImage);<br>
initializer->GeometryOn();<br>
initializer->InitializeTransform();<br>
<br>
<br>
transform->SetAngle(0.0);<br>
<br>
registration->SetInitialTransformParameters(transform->GetParameters());<br>
<br>
//we want to register movingImage against fixedImage<br>
registration->SetFixedImage(fixedImage);<br>
registration->SetMovingImage(movingImage);<br>
<br>
//we want to register the entire image<br>
registration->SetFixedImageRegion(fixedImage->GetLargestPossibleRegion());<br>
<br>
//now registration is ready<br>
typedef OptimizerType::ScalesType OptimizerScalesType;<br>
OptimizerScalesType optimizerScales(transform->GetNumberOfParameters());<br>
<br>
const Image2DType::SpacingType fixedSpacing = fixedImage->GetSpacing();<br>
const Image2DType::SizeType fixedSize = fixedImage->GetLargestPossibleRegion().GetSize();<br>
<br>
const double translationScale = 1.0 / (fixedSize[0] * fixedSpacing[0] * sqrt(2.0));<br>
<br>
optimizerScales[0] = 1.0;<br>
optimizerScales[1] = translationScale;<br>
optimizerScales[2] = translationScale;<br>
optimizerScales[3] = translationScale;<br>
optimizerScales[4] = translationScale;<br>
<br>
optimizer->SetScales(optimizerScales);<br>
<br>
GeneratorType::Pointer generator = GeneratorType::New();<br>
generator->Initialize(12345);<br>
optimizer->MaximizeOff();<br>
<br>
optimizer->SetNormalVariateGenerator(generator);<br>
optimizer->Initialize(10);<br>
optimizer->SetEpsilon(1.0);<br>
optimizer->SetMaximumIteration(400); //4000<br>
<br>
//add observer pattern to monitor evolution of optimization / registration process<br>
CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();<br>
optimizer->AddObserver(itk::IterationEvent(), observer);<br>
<br>
try<br>
{<br>
registration->StartRegistration();<br>
}<br>
catch(itk::ExceptionObject & err)<br>
{<br>
std::cerr << "ExceptionObject caught !" << std::endl;<br>
std::cerr << err << std::endl;<br>
exit(EXIT_FAILURE);<br>
}<br>
<br>
// get the registration parameters<br>
typedef RegistrationType::ParametersType ParametersType;<br>
ParametersType finalParameters = registration->GetLastTransformParameters();<br>
<br>
std::cout << -finalParameters[0] * 180.0 / vnl_math::pi << " " << finalParameters[3] << finalParameters[4] << std::endl;<br>
//final Output: 0 0 0 (same during entire process)<br>
}<br>
<br>
Thank you.<br>
--<br>
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -<br>
sicherer, schneller und einfacher! <a href="http://portal.gmx.net/de/go/chbrowser" target="_blank">http://portal.gmx.net/de/go/chbrowser</a><br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br>