# ITK metrics direct application

**URL:** <https://discourse.itk.org/t/itk-metrics-direct-application/2495>\
**Category:** Engineering\
**Tags:** registration\
**Created:** [December 9, 2019, 2:46pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495 "2019-12-09T14:46:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 9, 2019, 2:46pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/1 "2019-12-09T14:46:16Z")

</div>

Hey Guys!

**I’d like to hear form you if it is possible to apply itk similarity metrics (derived from `itkImagetoImageMetric.h`) directly for two images.**

The thing is: I’d like to used different similarity metrics to measure the similarity degree between tow images registered with different techniques.

I tried something like creating a metric, setting moving image and fixed image, and triggering `Update()`, but did not work.

**Any clue?**  
Thanks

---

<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:** [December 9, 2019, 2:54pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/2 "2019-12-09T14:54:51Z")

</div>

How about calling [`GetValue()`](https://itk.org/Doxygen/html/classitk_1_1SingleValuedCostFunction.html#a8d21f6a4fafb79760b61967a1617c380)?

---

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 9, 2019, 3:14pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/3 "2019-12-09T15:14:53Z")

</div>

I tried… But did not work…  
In fact, `ImageToImageMetrics` do no have `Update()` methods.  
I then called `GetValue()` directly.  
It outputs the following error:

```
terminate called after throwing an instance of 'itk::ExceptionObject'
what(): /home/leonardo/General-Sources/ITK- 
5.0.0/Modules/Numerics/Optimizersv4/include/itkObjectToObjectMetric.hxx:415:
itk::ERROR: MachadoMutualInformationImageToImageMetricv4(0x3155770): m_VirtualImage is 
undefined. Cannot return region. 
The program has unexpectedly finished.
```

---

<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:** [December 9, 2019, 4:14pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/4 "2019-12-09T16:14:28Z")

</div>

You might need to set some transform(s), even if it is identity.

---

<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:** [December 9, 2019, 4:19pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/5 "2019-12-09T16:19:08Z")

</div>

Also these topics might be interesting:

> [@Image registration metric derivative](https://discourse.itk.org/t/image-registration-metric-derivative/1200):
>
> 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 me…

> [@Metric to evaluate the registration accuracy on 3D MRI](https://discourse.itk.org/t/metric-to-evaluate-the-registration-accuracy-on-3d-mri/2426):
>
> Hello, I am a newbie to ITK registration. Currently, I am implementing intra-subject registration of 3D PET (moving image) into 3D MRI (fixed image) using ITK. I want to check the registration accuracy which is the error in distance between transformed PET and fixed MRI images. How can I do that in ITK C++? Are there any available examples? Thanks in advance.

> [@New to ITK - moving from ImageJ macros - SimpleITK arithmetic Q](https://discourse.itk.org/t/new-to-itk-moving-from-imagej-macros-simpleitk-arithmetic-q/2101/5):
>
> Thanks for the reply Dženan, When I take a single image and translate/rotate a copy, then run registration, the mean square reported goes from a high at the start of 650,000 to a fitted value of 300,000. You can see this in the images below, showing the metric as well as the fitted image overlaid the “original”. So these images are identical - except for translation/rotation. So I would expect that a mean squares metric would be essentially zero. (assuming its a mean squared difference that…

---

<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:** [December 9, 2019, 4:57pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/6 "2019-12-09T16:57:15Z")

</div>

The [Compute Mean Squares Metric Between Two Images](https://itk.org/ITKExamples/src/Registration/Common/ComputeMeanSquareBetweenTwoImages/Documentation.html) example may be helpful.

---

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 9, 2019, 5:11pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/7 "2019-12-09T17:11:50Z")

</div>

Great!!!  
I guess that is exactly what I was looking for.

Thanks guys!

---

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 9, 2019, 5:40pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/8 "2019-12-09T17:40:57Z")

</div>

It worked… Uhul!

In the `RegistrationV4` examples, usually, they do not set `interpolator`. Does the `default interpolator` is the linear one?

---

<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:** [December 9, 2019, 7:23pm UTC](https://discourse.itk.org/t/itk-metrics-direct-application/2495/9 "2019-12-09T19:23:52Z")

</div>

Linear interpolator is the default one, if there is a default.
