# Correlation of two images

**URL:** <https://discourse.itk.org/t/correlation-of-two-images/2815>\
**Category:** Uncategorized\
**Created:** [March 11, 2020, 3:31am UTC](https://discourse.itk.org/t/correlation-of-two-images/2815 "2020-03-11T03:31:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)\
**Post date:** [March 11, 2020, 3:31am UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/1 "2020-03-11T03:31:16Z")

</div>

How do I perform the correlation between two patches that I extracted from an image?  
I have extracted two patches and saved them into two different images. Now I just want to perform correlation between them. There is no template image for me. My both images are of same size and type.

Im using flipimagefilter followed by simple Itkconvolutionimagefilter to perform correlation operation.  
If my two images are of size 5_5_5, how do I print the value of correlation? (I dont want to do any padding for the images. I just need the output correlation value as 1_1_1)

---

<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:** [March 11, 2020, 2:02pm UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/3 "2020-03-11T14:02:28Z")

</div>

What you seem to want is to evaluate an image similarity metric for your two images. If so, please look at [ITK metrics direct application](https://discourse.itk.org/t/itk-metrics-direct-application/2495) and [Is there a decent way to quantify the “goodness” of a CT to CT scan registration?](https://discourse.itk.org/t/is-there-a-decent-way-to-quantify-the-goodness-of-a-ct-to-ct-scan-registration/2066)

---

<div class="post-metadata">

**Author:** ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)\
**Post date:** [March 31, 2020, 4:12pm UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/4 "2020-03-31T16:12:24Z")

</div>

I am actually trying to find the correlation value pixel wise. I need a correlation map that is of the size of my input image. `itkMskedFFTNormalizedcorrelationfilter.h` gives me double sized image.

---

<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:** [March 31, 2020, 4:53pm UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/5 "2020-03-31T16:53:24Z")

</div>

I guess it computes correlation for both positive and negative translations, thus making an output which is 2\*n-1 in size.

---

<div class="post-metadata">

**Author:** ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)\
**Post date:** [March 31, 2020, 5:01pm UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/6 "2020-03-31T17:01:38Z")

</div>

Is there any way to make it to size ‘n’ ?

---

<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:** [March 31, 2020, 5:12pm UTC](https://discourse.itk.org/t/correlation-of-two-images/2815/7 "2020-03-31T17:12:33Z")

</div>

Take the middle part? I think that implies less extreme translations, but you should check the documentation and/or source code of that filter.
