Adding a vtkImageDifference test

dev
Mathieu Westphal 2 months ago
parent 198f099a49
commit 4305330788

@ -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;
}

@ -0,0 +1 @@
d433e15a7e9bfb3b03eb5b5c73d3956782fd1f5662008ceb5180600202c87e4c47e541c4409c1bca5a6083183f3a005aeb70155c218a9977478ae9900d773963

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