Merge topic 'fix_vtkImageDifference_release' into release

e2912082ff Adding/Updating baselines
2ab1c0255b Adding a md file
022ebdaf1c Adding a vtkImageDifference test
ffeacbe2ed Fix vtkImageDifference issues

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Charles Gueunet <charles.gueunet@kitware.com>
Merge-request: !9716
dev
Mathieu Westphal 2 months ago committed by Kitware Robot
commit 9382d9eefb

@ -0,0 +1,8 @@
# Fixing an impacting issue in vtkImageDifference
A impacting issue in vtkImageDifference has been fixed.
Between vtk 9.1 and 9.2, an change has been made to vtkImageDifference
that causes different image to be identified as not different
depending on how the vtkImageDifference was configured.
This fix may causes some testing to start failing.

@ -0,0 +1 @@
f63d1e9f84655024083b28bd6eaa238f0600dace14ed37e513cfda77d94e3c3ac7053b1d7d1866379aeda58720e766f526fe1c716c942d653c0081192f18d03a

@ -1,4 +1,6 @@
vtk_module_test_data(
Data/ImageDiff1.png
Data/ImageDiff2.png
Data/beach.tif
Data/fullhead15.png
Data/headsq/,REGEX:.*)

@ -4,6 +4,7 @@ vtk_add_test_cxx(vtkImagingCoreCxxTests tests
ImageAccumulateLarge.cxx,NO_VALID,NO_DATA,NO_OUTPUT 32
ImageAutoRange.cxx
ImageBSplineCoefficients.cxx
ImageDifference.cxx,NO_VALID
ImageGenericInterpolateSlidingWindow3D.cxx
ImageHistogram.cxx
ImageHistogramStatistics.cxx,NO_VALID

@ -0,0 +1,142 @@
/*=========================================================================
Program: Visualization Toolkit
Module: ImageDifference.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Test the vtkImageDifference class
#include "vtkImageDifference.h"
#include "vtkMathUtilities.h"
#include "vtkNew.h"
#include "vtkPNGReader.h"
#include "vtkTestUtilities.h"
#include <iostream>
#include <limits>
namespace
{
bool CheckErrors(vtkImageDifference* differenceFilter, double expectedError,
double expectedThresholdedError, const std::string& info)
{
if (!vtkMathUtilities::FuzzyCompare(differenceFilter->GetError(), expectedError, 1e-8) ||
!vtkMathUtilities::FuzzyCompare(
differenceFilter->GetThresholdedError(), expectedThresholdedError, 1e-8))
{
std::cerr << std::setprecision(std::numeric_limits<double>::digits10);
std::cerr << std::setprecision(17);
std::cerr << "Unexpected vtkImageDifference errors with " << info << std::endl;
std::cerr << "Expected error: " << expectedError << ", got: " << differenceFilter->GetError()
<< " " << (expectedError != differenceFilter->GetError()) << std::endl;
std::cerr << "Expected thresholded error: " << expectedThresholdedError
<< ", got: " << differenceFilter->GetThresholdedError() << " "
<< (expectedThresholdedError != differenceFilter->GetThresholdedError()) << std::endl;
return false;
}
return true;
}
}
int ImageDifference(int argc, char* argv[])
{
char* fname1 = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/ImageDiff1.png");
char* fname2 = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/ImageDiff2.png");
vtkNew<vtkPNGReader> reader1;
reader1->SetFileName(fname1);
reader1->Update();
vtkNew<vtkPNGReader> reader2;
reader2->SetFileName(fname2);
reader2->Update();
delete[] fname1;
delete[] fname2;
vtkNew<vtkImageDifference> differenceFilter;
differenceFilter->SetInputConnection(reader1->GetOutputPort());
differenceFilter->SetImageConnection(reader2->GetOutputPort());
// Default param
differenceFilter->Update();
if (!::CheckErrors(
differenceFilter, 10600.898039215839, 0.97124183006535825, "default parameters"))
{
return EXIT_FAILURE;
}
// Testing symmetric
differenceFilter->SetInputConnection(reader2->GetOutputPort());
differenceFilter->SetImageConnection(reader1->GetOutputPort());
differenceFilter->Update();
if (!::CheckErrors(
differenceFilter, 10600.898039215839, 0.97124183006535825, "symmetric testing"))
{
return EXIT_FAILURE;
}
// Zero threshold
differenceFilter->SetThreshold(0);
differenceFilter->Update();
if (!::CheckErrors(differenceFilter, 9342.9607843138092, 9342.9607843138092, "zero threshold"))
{
return EXIT_FAILURE;
}
// Higher average threshold
differenceFilter->SetThreshold(105);
differenceFilter->SetAverageThresholdFactor(1.);
differenceFilter->Update();
if (!::CheckErrors(
differenceFilter, 10594.431372549172, 0.22614379084967323, "higher average threshold"))
{
return EXIT_FAILURE;
}
// No averaging
differenceFilter->SetAverageThresholdFactor(0.5);
differenceFilter->SetAveraging(false);
differenceFilter->Update();
if (!::CheckErrors(differenceFilter, 10600.898039215839, 0.97124183006535825, "no averaging"))
{
return EXIT_FAILURE;
}
// No shift
differenceFilter->SetAveraging(true);
differenceFilter->SetAllowShift(false);
differenceFilter->Update();
if (!::CheckErrors(differenceFilter, 9587.1254901961565, 1.1986928104575143, "no shift"))
{
return EXIT_FAILURE;
}
// Multi param
differenceFilter->SetThreshold(0);
differenceFilter->SetAveraging(false);
differenceFilter->Update();
if (!::CheckErrors(
differenceFilter, 9587.1254901961565, 9587.1254901961565, "multiple parameters changes"))
{
return EXIT_FAILURE;
}
// Identical
differenceFilter->SetInputConnection(reader1->GetOutputPort());
differenceFilter->Update();
if (!::CheckErrors(differenceFilter, 0., 0., "identical images"))
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

@ -25,6 +25,7 @@
#include <numeric>
constexpr int MAX_NCOMPS = 4;
constexpr double DEFAULT_ERROR = 1000.;
using max_ncomps_array_t = std::array<int, MAX_NCOMPS>;
vtkStandardNewMacro(vtkImageDifference);
@ -317,7 +318,6 @@ void vtkImageDifference::ThreadedRequestData(vtkInformation* vtkNotUsed(request)
max_ncomps_array_t rgbaMax;
rgbaMax.fill(0);
max_ncomps_array_t rgbaTresh;
rgbaTresh.fill(1000);
// ignore the boundary within two pixels as we cannot
// do a good average calc on the boundary
@ -326,6 +326,7 @@ void vtkImageDifference::ThreadedRequestData(vtkInformation* vtkNotUsed(request)
{
for (int direction = 0; direction <= 1; ++direction)
{
rgbaTresh.fill(DEFAULT_ERROR);
unsigned char* dir1Ptr0 = direction == 0 ? in1Ptr0 : in2Ptr0;
unsigned char* dir2Ptr0 = direction == 0 ? in2Ptr0 : in1Ptr0;
bool haveValues = false;
@ -401,7 +402,7 @@ void vtkImageDifference::ThreadedRequestData(vtkInformation* vtkNotUsed(request)
std::copy(rgbaMax.begin(), rgbaMax.end(), rgbaTresh.begin());
error += std::accumulate(rgbaTresh.begin(), rgbaTresh.end(), 0) / (nComp * 255);
error += std::accumulate(rgbaTresh.begin(), rgbaTresh.end(), 0.) / (nComp * 255.);
for (int i = 0; i < nComp; i++)
{
@ -410,7 +411,7 @@ void vtkImageDifference::ThreadedRequestData(vtkInformation* vtkNotUsed(request)
*outPtr0++ = static_cast<unsigned char>(rgbaTresh[i]);
}
thresholdedError +=
std::accumulate(rgbaTresh.begin(), rgbaTresh.end(), 0) / (nComp * 255.0);
std::accumulate(rgbaTresh.begin(), rgbaTresh.end(), 0.) / (nComp * 255.);
in1Ptr0 += nComp;
in2Ptr0 += nComp;
@ -489,8 +490,8 @@ int vtkImageDifference::RequestData(
// Report errors here, do not report errors while multithreading!
vtkErrorMacro("RequestData: " << this->ErrorMessage);
this->ErrorMessage = nullptr;
this->Error = 1000.0;
this->ThresholdedError = 1000.0;
this->Error = DEFAULT_ERROR;
this->ThresholdedError = DEFAULT_ERROR;
ret = 0;
}
@ -515,8 +516,8 @@ int vtkImageDifference::RequestInformation(vtkInformation* vtkNotUsed(request),
if (in1Ext[0] != in2Ext[0] || in1Ext[1] != in2Ext[1] || in1Ext[2] != in2Ext[2] ||
in1Ext[3] != in2Ext[3] || in1Ext[4] != in2Ext[4] || in1Ext[5] != in2Ext[5])
{
this->Error = 1000.0;
this->ThresholdedError = 1000.0;
this->Error = DEFAULT_ERROR;
this->ThresholdedError = DEFAULT_ERROR;
vtkErrorMacro("ExecuteInformation: Input are not the same size.\n"
<< " Input1 is: " << in1Ext[0] << "," << in1Ext[1] << "," << in1Ext[2] << "," << in1Ext[3]

@ -0,0 +1 @@
6f14a3f8233cf495e8ee9f6cb73f5a65005205c9bc990a220b3ca796e5ef415dfc5ccb8a8aa89163c852db916c2acd62953b9655d9f51a87b32329cf483ea46a

@ -1 +1 @@
c00399d5d0475dd85d6a65f51e5a3ccbb506c2976470750947900f69581a4ba4a73bcd6533d5823731eda5e67d64d606871762e548efe6824cdb2dd05cdfd128
18eeb74ffc34aa56acbb93270759b9fa3330c337bd590fe7719412706c0bf12ddfafe075f9b9b8dada33956a91d80cc6b2309dccfb8baf4195c3bd239846759e

@ -1 +1 @@
9015c94269f3c4d7e3a9479b770088e517c6f6806edb9d661235ebd1e88ad4e314a8aac2e46cd86519be3a34cfeb4a71bd15c11565b369060f511bc1084200ca
bf21dc2f47d4e467c1867853026955d70149f1b5efe918ad4e818ae01be00dcd3fc3191842a76707d1875c1cda52f0854191230883661d4cb69806f7065d9dcc

@ -0,0 +1 @@
d433e15a7e9bfb3b03eb5b5c73d3956782fd1f5662008ceb5180600202c87e4c47e541c4409c1bca5a6083183f3a005aeb70155c218a9977478ae9900d773963

@ -0,0 +1 @@
2f6bf435136d567d6f9a4199f657073002f39d6c83dafac64223f6f6bb8d3af13cfe8c43f2e781695caff1f13019e02f58007f4d042c85c0eee3211f38758ce8
Loading…
Cancel
Save