# Gradient magnitude (0) at the first iteration

**URL:** https://discourse.itk.org/t/gradient-magnitude-0-at-the-first-iteration/5628
**Category:** Algorithms
**Tags:** registration
**Created:** [January 14, 2023, 2:27pm UTC](https://discourse.itk.org/t/gradient-magnitude-0-at-the-first-iteration/5628 "2023-01-14T14:27:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![suzume](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@suzume](https://discourse.itk.org/u/suzume)
#### Post date: [January 14, 2023, 2:27pm UTC](https://discourse.itk.org/t/gradient-magnitude-0-at-the-first-iteration/5628/1 "2023-01-14T14:27:49Z")

</div>

Hi, the iteration stopped at the first iteration no matter what the initial transform parameters are and the stop reason is " RegularStepGradientDescentOptimizer: Gradient magnitude tolerance met after 0 iterations. Gradient magnitude (0) is less than gradient magnitude tolerance (0.0001)."

 ![截屏2023-01-14 22.35.13](https://discourse.itk.org/uploads/default/original/2X/8/8df34566f6cde1e9d4775ea4910ce1751e1e690f.png)

 ![截屏2023-01-14 22.33.02](https://discourse.itk.org/uploads/default/original/2X/3/330d27e3546df8f79a9f090f3ee43b51ae238896.png)  
In the two pictures, the changes of metric values are small but not zero, so the gradient should not be zero, right?

The optimizer, metric and registration method are itkRegularStepGradientDescentOptimizer.h , itkMattesMutualInformationImageToImageMetric.h and itkMultiResolutionImageRegistrationMethod.h, respectively. However, when I change the metric to itkGradientDifferenceImageToImageMetric.h, it can run normally and will not stop at the first iteration. But the metric value is too large and the gradient is also too large. So maybe the itkGradientDifferenceImageToImageMetric.h is a not suitable metric for the registration.

 ![截屏2023-01-14 22.45.23](https://discourse.itk.org/uploads/default/original/2X/8/88d41d15626552656554794166ed7c5008d66e89.png)

Someone else has posed " [Gradient magnitude (0) in registration.](https://discourse.itk.org/t/gradient-magnitude-0-in-registration/2266)" and the solutions in her topic seems not help to my problem. What else can I do to solve this problem?
