# vtkImageDifference does not detect different images

**URL:** https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935
**Category:** Development
**Created:** [December 19, 2023, 3:10pm UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935 "2023-12-19T15:10:17Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![guillaume\_Peillex](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_peillex/32/8171_2.png) [@guillaume\_Peillex](https://discourse.vtk.org/u/guillaume_Peillex)
#### Post date: [December 19, 2023, 3:10pm UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/1 "2023-12-19T15:10:17Z")

</div>

Hi all,

In the CI of Themys, our `ParaView Branded Application`, we use the module `Testing.py` which makes use of the `vtkImageDifference` algorithm.

It seems that with default configuration this algorithm does not detect that the two images below are different.

 ![hic_different_reloads_0](https://discourse.vtk.org/uploads/default/original/2X/5/5977c88a42999d29baea266c009a2cdca93890c0.png)  
 ![hic_different_reloads_0.valid](https://discourse.vtk.org/uploads/default/original/2X/c/c500e5eb8f343ae5f896587fd2345ef01c1a09e8.png)

After reading [vtkImageDifference does not detect image differences - #6 by mwestphal](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-image-differences/9726/6) i tried to add `idiff.SetThreshold(0)` in `Testing.py` and with this modification the images are correctfully detected as different.

I do not know if it is a known corner case of the `vtkImageDifference` algorithm or a bug.  
By the way should i use a custom python script with `idiff.SetThreshold`?

Thanks in advance

G.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [December 19, 2023, 3:42pm UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/2 "2023-12-19T15:42:09Z")

</div>

It is a known issue. We are currently in the process of changing the metric used for image comparison in regression testing (see [here](https://discourse.vtk.org/t/enhancing-vtks-image-testing-framework-a-transition-to-ssim-and-lab-channels/12584)). This will be quite impactful for VTK and projects depending on it so it will be opt in at first. The current metric is too forgiving and does not capture enough information in the image to be satisfactory.

---

<div class="post-metadata">

### Author: ![guillaume\_Peillex](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_peillex/32/8171_2.png) [@guillaume\_Peillex](https://discourse.vtk.org/u/guillaume_Peillex)
#### Post date: [December 20, 2023, 7:41am UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/3 "2023-12-20T07:41:05Z")

</div>

Ok. Thanks for this quick answer @Yohann_Bearzi

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [December 20, 2023, 10:54am UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/4 "2023-12-20T10:54:52Z")

</div>

> [@Yohann\_Bearzi](#):
>
> It is a known issue

TBH making the treshold default to zero and improving the doc would be a very simple test, especially considering that the new class will not replace the old class for compat reasons.

---

<div class="post-metadata">

### Author: ![guillaume\_Peillex](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_peillex/32/8171_2.png) [@guillaume\_Peillex](https://discourse.vtk.org/u/guillaume_Peillex)
#### Post date: [December 20, 2023, 11:06am UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/5 "2023-12-20T11:06:23Z")

</div>

@mwestphal @Yohann_Bearzi If i understand and read correctly the source code, i can have the strictest options for comparison by typing:

```auto
    # Here we want to be as strict as possible so do not set threshold
    idiff.SetThreshold(0)
    # Do not compare images by allowing a shift of two pixels between images
    idiff.SetAllowShift(False)
    # Do not compare averaged 3x3 data between the images
    idiff.SetAveraging(False)

```

Am i right?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [December 20, 2023, 12:24pm UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/6 "2023-12-20T12:24:08Z")

</div>

Indeed, but expect the result to almost never be zero.

---

<div class="post-metadata">

### Author: ![guillaume\_Peillex](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_peillex/32/8171_2.png) [@guillaume\_Peillex](https://discourse.vtk.org/u/guillaume_Peillex)
#### Post date: [December 20, 2023, 1:01pm UTC](https://discourse.vtk.org/t/vtkimagedifference-does-not-detect-different-images/12935/7 "2023-12-20T13:01:15Z")

</div>

Ok. Thanks @mwestphal
