Hi all,
I am using itk.RegularStepGradientDescentOptimizerv4 to perform a multiresolution translation registration between two images. I ran my code in the same computation environment for the same two images at different times, but I got a slightly different results (please see the attached figures) during the iterations. I checked the results and found the difference mostly starting from the middle level of a image pyramid (I used 3-level image pyramid), and then the difference would be increased and increased, something like “butterfly effect”. Actually, I have applied “ReturnBestParametersAndValueOn” for itk.RegularStepGradientDescentOptimizerv4. So I wonder is the phenomenon normal? If it is normal, how can I avoid this kind of unstable iteration as much as possible? Thanks in advance.
Regards,
Zhuangming Shen
Here is some parts of my code.
translation_registration = itk.ImageRegistrationMethodv4[itk.Image.F3, itk.Image.F3].New()
translation_interpolator_fixed_image = itk.LinearInterpolateImageFunction[itk.Image.F3, itk.D].New()
translation_interpolator_moving_image = itk.LinearInterpolateImageFunction[itk.Image.F3, itk.D].New()
translation_metric = itk.MattesMutualInformationImageToImageMetricv4[itk.Image.F3, itk.Image.F3].New()
translation_metric.SetFixedInterpolator(translation_interpolator_fixed_image)
translation_metric.SetMovingInterpolator(translation_interpolator_moving_image)
translation_metric.SetFixedImageMask(fixed_object)
translation_metric.SetNumberOfHistogramBins(32)
translation_transform = itk.TranslationTransform[itk.D, 3].New()
translation_optimizer_scales = itk.OptimizerParametersitk.D
translation_optimizer_scales.SetSize(translation_transform.GetNumberOfParameters())
translation_optimizer_scales.SetElement(0, 1.0) # x translation
translation_optimizer_scales.SetElement(1, 1.0) # y translation
translation_optimizer_scales.SetElement(2, 1.0) # z translation
translation_optimizer = itk.RegularStepGradientDescentOptimizerv4[itk.D].New()
translation_optimizer.SetScales(translation_optimizer_scales)
translation_optimizer.SetNumberOfIterations(100)
translation_optimizer.SetLearningRate(6.0)
translation_optimizer.SetMinimumStepLength(1e-1)
translation_optimizer.SetDoEstimateLearningRateAtEachIteration(True)
translation_optimizer.ReturnBestParametersAndValueOn()
translation_registration.SetFixedImage(caster_fixed_image.GetOutput())
translation_registration.SetMovingImage(caster_moving_image.GetOutput())
translation_registration.SetMetric(translation_metric)
translation_registration.SetOptimizer(translation_optimizer)
translation_registration.SetInitialTransform(translation_transform)
translation_registration.SetShrinkFactorsPerLevel([4, 2, 1])
translation_registration.SetMetricSamplingPercentagePerLevel([1,1,1])
def iterationUpdate():
current_parameters = translation_registration.GetOutput().Get().GetParameters()
print "[%d] optimizer value: %f current step length: %f current parameters: %f %f %f " %(translation_optimizer.GetCurrentIteration(), translation_optimizer.GetValue(), translation_optimizer.GetCurrentStepLength(), current_parameters.GetElement(0), current_parameters.GetElement(1), current_parameters.GetElement(2))
iteration_command = itk.PyCommand.New()
iteration_command.SetCommandCallable(iterationUpdate)
translation_optimizer.AddObserver(itk.IterationEvent(), iteration_command)
translation_registration.Update()