# Image registration metric derivative

**URL:** <https://discourse.itk.org/t/image-registration-metric-derivative/1200>\
**Category:** Algorithms\
**Created:** [August 14, 2018, 3:32pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200 "2018-08-14T15:32:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [August 14, 2018, 3:32pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/1 "2018-08-14T15:32:55Z")

</div>

I am using image registration for some time now but I am still trying to understand things in more deep. It seems tracing ITK code is not that easy.

What is the math behind the metric derivative and where can I find the implementation part i.e the update function of the transform parameters? it would be nice if someone provide explanation or some simple-to-read references.

Assuming a 2D rigid transformation with only 3 parameters translation in x and y, and a rotation angle; assuming also a mean squared error metric, how is the metric derivative and the update equation look like?

is extend the concept to 3D is straight forward or involving more math and code?

I hope the questions are clear!  
Thanks!

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [August 15, 2018, 2:21pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/2 "2018-08-15T14:21:52Z")

</div>

The following resources may be useful:

- The [ITKv4 Image Registration Framework](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4009425/) article
- The [Registration Chapter of the ITK Software Guide](https://itk.org/ITKSoftwareGuide/html/Book2/ITKSoftwareGuide-Book2ch3.html#x26-980003)
- John Galeotti’s Course’s [ITK Registration Chapter](https://www.cs.cmu.edu/~galeotti/methods_course/ITK_Registration.pptx)
- Materials from the many [university courses based on ITK](https://blog.kitware.com/courses-in-medical-image-analysis-that-use-itk/)

But, the source code is the ultimate authority.

---

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [August 15, 2018, 3:25pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/3 "2018-08-15T15:25:55Z")

</div>

Thanks Matt for your concern. What I am looking is more details about the metric derivative. I already went through the links you provided but couldn’t find a clear answer.  
If you take a look at the paper in the first link, details about equation 2 is what I need (by the way, I found the same equation in [this](https://link.springer.com/chapter/10.1007/978-3-642-31340-0_28) paper as well) .

I like to know:

1. How this derivative computed in more details.
2. How to implement this equation e.g. pseudo code or the part in itk that does it.

Thanks!

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [August 15, 2018, 3:57pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/4 "2018-08-15T15:57:40Z")

</div>

The code that implements Equation 2 for the first link for the mean squares metric is here:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/6b41fe1cbf7a71a6003d4824e02a69b41a508cda/Modules/Registration/Metricsv4/include/itkMeanSquaresImageToImageMetricv4GetValueAndDerivativeThreader.hxx#L42-L83>

It is a bit complicated because common computation is spread across the class hierarchy. To inspect the hierarchy, see [the class’s Doxyen page](https://itk.org/Doxygen/html/classitk_1_1MeanSquaresImageToImageMetricv4.html).

We could make these classes easier to follow and more performant if we replaced the _DomainThreader_ classes with the ITK 5 multi-threading API, described in the [Multi-Threading section of the ITK Software Guide](https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch3.html#x39-310003.1).

---

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [August 15, 2018, 4:04pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/5 "2018-08-15T16:04:48Z")

</div>

Thanks a lot, I will give it a try.

> It is a bit complicated

Indeed , probably a dedicated book/course on ITK registration would be a good idea to explain the theory and the implementation.

---

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [October 11, 2018, 1:00pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/6 "2018-10-11T13:00:28Z")

</div>

> `/* Use a pre-allocated jacobian object for efficiency */ using JacobianReferenceType = typename TImageToImageMetric::JacobianType &; JacobianReferenceType jacobian = this->m_GetValueAndDerivativePerThreadVariables[threadId].MovingTransformJacobian; JacobianReferenceType jacobianPositional = this->m_GetValueAndDerivativePerThreadVariables[threadId].MovingTransformJacobianPositional;`

I kept tracing it but I could not find where the computation of Jacobian implemented. Could you please add a link to it.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [October 11, 2018, 2:41pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/7 "2018-10-11T14:41:34Z")

</div>

Each transform type can provide its own way to compute a Jacobian. The base implementation for “4x4 transform matrix” is here:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/5142ed7bb5e4e5042734fc47bf556a2342be6cec/Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx#L647-L673>

---

<div class="post-metadata">

**Author:** ![ibr](https://discourse.itk.org/user_avatar/discourse.itk.org/ibr/32/468_2.png) [@ibr](https://discourse.itk.org/u/ibr)\
**Post date:** [October 11, 2018, 2:49pm UTC](https://discourse.itk.org/t/image-registration-metric-derivative/1200/8 "2018-10-11T14:49:38Z")

</div>

Thanks, this is really helpful.
