[Insight-users] How to get number of iterations from optimizer?

motes motes mort.motes at gmail.com
Tue Dec 8 13:17:29 EST 2009


I have an image registration process where I use the
RegularGradientDescentOptimizer:

  typename RegularGradientDescentOptimizerType::Pointer optimizer =
RegularGradientDescentOptimizerType::New();

          optimizer->SetMaximumStepLength( 0.5 );
          optimizer->SetMinimumStepLength( 0.0001 );
          optimizer->SetGradientMagnitudeTolerance( 0.0001 );
          optimizer->SetNumberOfIterations( 1000 );
          optimizer->MinimizeOn();
          ObserverType::Pointer Observer = ObserverType::New();
          optimizer->AddObserver( itk::IterationEvent(), Observer );
          registration->SetOptimizer( optimizer );


When the image registration method is done:

    try {
      timeProbe.Start();
      registration->Update();
      timeProbe.Stop();
    }
    catch( itk::ExceptionObject & err ) {
      std::cerr << "ExceptionObject caught !" << std::endl;
      std::cerr << err << std::endl;
      return;
    }


its possible to get the final metric value with:


   double final_metric_value =
registration->GetOptimizer()->GetValue(registration->GetLastTransformParameters());


But its not possible to get the number of used iterations like
(sometimes the optimizer terminates before the maximum number of
iterations has been used):


  int used_iterations =  registration->GetOptimizer()->GetNumberOfIterations();

Error:

Error	12	error C2039: 'GetNumberOfIterations' : is not a member of
'itk::SingleValuedNonLinearOptimizer'

It there someway to cast the base optimizer class to the
RegularGradientDescentOptimizerType (this subclass has the function
GetNumberOfIterations) ?


More information about the Insight-users mailing list