# Compare two images of any kind

**URL:** https://discourse.itk.org/t/compare-two-images-of-any-kind/543
**Category:** Beginner Questions
**Created:** [December 19, 2017, 2:11pm UTC](https://discourse.itk.org/t/compare-two-images-of-any-kind/543 "2017-12-19T14:11:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mschwier](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mschwier](https://discourse.itk.org/u/mschwier)
#### Post date: [December 19, 2017, 2:12pm UTC](https://discourse.itk.org/t/compare-two-images-of-any-kind/543/1 "2017-12-19T14:12:04Z")

</div>

Is there an easy way to compare two images for equality that also supports Vector Images?

Right now I am using the old itkTestMain.h 😕 which uses the itkTestingComparisonImageFilter and does not support Vector Images.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [December 19, 2017, 2:22pm UTC](https://discourse.itk.org/t/compare-two-images-of-any-kind/543/2 "2017-12-19T14:22:49Z")

</div>

This is an unfortunate limitation of the current method.

For SimpleITK testing we implemented a function which works with scalars, vector images, and images of complex numbers. It computes the root means squares:

> <https://github.com/SimpleITK/SimpleITK/blob/c9f21b20ebb1d2b0a6577578bd7e0cb6251e9cf8/Testing/Unit/sitkImageCompare.cxx#L95-L127>

This is build upon SimpleITK’s typeless layer, but could be ported to native ITK Filter and many people would find it useful. Dealing with the different pixel types may require some C++ meta-programming, new C++11 features may make this easier to do now.

---

<div class="post-metadata">

### Author: ![mschwier](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mschwier](https://discourse.itk.org/u/mschwier)
#### Post date: [December 19, 2017, 2:50pm UTC](https://discourse.itk.org/t/compare-two-images-of-any-kind/543/3 "2017-12-19T14:50:43Z")

</div>

Thanks for your answer. I’ll see if I can switch to SimpleITK or try to port it to native ITK.

---

<div class="post-metadata">

### Author: ![fedorov](https://discourse.itk.org/user_avatar/discourse.itk.org/fedorov/32/207_2.png) [@fedorov](https://discourse.itk.org/u/fedorov)
#### Post date: [December 28, 2017, 8:46pm UTC](https://discourse.itk.org/t/compare-two-images-of-any-kind/543/4 "2017-12-28T20:46:39Z")

</div>

For the reference, and in case someone else needs this, @mschwier implemented this comparison separately in our library by comparing all vector components (this is what makes sense for our use case), see [https://github.com/millerjv/PkModeling/pull/69/commits/82faac4729dae139c84c9c661fbe349bc30b5d08](https://github.com/millerjv/PkModeling/pull/69/commits/82faac4729dae139c84c9c661fbe349bc30b5d08)
