Hi all,
I saw the example of MultiResImageRegistration1.cxx can change the optimizer parameters (e.g learning rate) for different level of a image pyramid. But when I learnt from it to write python-supported ITK code, the optimizer parameters did not change. Did I miss something in the code below? Thanks in advance.
Here is my code
rigid_registration = itk.ImageRegistrationMethodv4[itk.Image.F3, itk.Image.F3].New()
rigid_optimizer = itk.RegularStepGradientDescentOptimizerv4[itk.D].New()
rigid_optimizer.SetScales(rigid_optimizer_scales)
rigid_optimizer.ReturnBestParametersAndValueOn()
if rigid_registration.GetCurrentLevel() == 0:
rigid_optimizer.SetLearningRate(16.0)
rigid_optimizer.SetMinimumStepLength(2.5)
else:
rigid_optimizer.SetLearningRate(rigid_optimizer.GetCurrentStepLength())
rigid_optimizer.SetMinimumStepLength(rigid_optimizer.GetMinimumStepLength()*0.2)
registration
rigid_registration.SetFixedImage(caster_fixed_image.GetOutput())
rigid_registration.SetMovingImage(caster_moving_image.GetOutput())
rigid_registration.SetMetric(rigid_metric)
rigid_registration.SetOptimizer(rigid_optimizer)
rigid_registration.SetInitialTransform(rigid_transform)
def iterationUpdate():
print(rigid_optimizer.GetLearningRate())
iteration_command = itk.PyCommand.New()
iteration_command.SetCommandCallable(iterationUpdate)
rigid_optimizer.AddObserver(itk.IterationEvent(), iteration_command)
rigid_registration.Update()