mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Created RGB to monochrome filters.
This commit is contained in:
parent
b13ccab303
commit
689957c80b
4 changed files with 37 additions and 23 deletions
|
@ -12,26 +12,28 @@
|
|||
|
||||
#include <itkRGBPixel.h>
|
||||
#include <itkImage.h>
|
||||
#include <itkImageFileReader.h>
|
||||
#include <itkImageFileWriter.h>
|
||||
#include <itkRGBToLuminanceImageFilter.h>
|
||||
|
||||
float ITKImageComparer::compareImages(QString file1, QString file2) const {
|
||||
using PixelType = itk::RGBPixel<unsigned char>;
|
||||
using ImageType = itk::Image<PixelType, 2>;
|
||||
ITKImageComparer::ITKImageComparer() {
|
||||
// These are smart pointers that do not need to be deleted
|
||||
actualImageReader = ReaderType::New();
|
||||
expectedImageReader = ReaderType::New();
|
||||
}
|
||||
|
||||
using ReaderType = itk::ImageFileReader<ImageType>;
|
||||
using WriterType = itk::ImageFileWriter<ImageType>;
|
||||
float ITKImageComparer::compareImages(QString actualImageFilename, QString expectedImageFilename) const {
|
||||
actualImageReader->SetFileName(actualImageFilename.toStdString().c_str());
|
||||
expectedImageReader->SetFileName(expectedImageFilename.toStdString().c_str());
|
||||
|
||||
ReaderType::Pointer reader = ReaderType::New();
|
||||
WriterType::Pointer writer = WriterType::New();
|
||||
|
||||
reader->SetFileName(file1.toStdString().c_str());
|
||||
writer->SetFileName("D:/pics/loni.jpg");
|
||||
|
||||
ImageType::Pointer image = reader->GetOutput();
|
||||
writer->SetInput(image);
|
||||
|
||||
writer->Update();
|
||||
// Images are converted to monochrome for comparison
|
||||
using MonochromePixelType = unsigned char;
|
||||
using MonochromeImageType = itk::Image<MonochromePixelType, Dimension>;
|
||||
using FilterType = itk::RGBToLuminanceImageFilter<RGBImageType, MonochromeImageType>;
|
||||
|
||||
FilterType::Pointer actualImageToMonochrome = FilterType::New();
|
||||
FilterType::Pointer expectedImageToMonochrome = FilterType::New();
|
||||
|
||||
actualImageToMonochrome->SetInput(actualImageReader->GetOutput());
|
||||
expectedImageToMonochrome->SetInput(expectedImageReader->GetOutput());
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
|
|
@ -12,11 +12,23 @@
|
|||
|
||||
#include "ImageComparer.h"
|
||||
|
||||
#include <itkImage.h>
|
||||
#include <itkImageFileReader.h>
|
||||
|
||||
class ITKImageComparer : public ImageComparer {
|
||||
public:
|
||||
float compareImages(QString file1, QString file2) const final;
|
||||
ITKImageComparer();
|
||||
float compareImages(QString actualImageFilename, QString expectedImageFilename) const final;
|
||||
|
||||
private:
|
||||
static const unsigned int Dimension{ 2 };
|
||||
|
||||
using RGBPixelType = itk::RGBPixel<unsigned char>;
|
||||
using RGBImageType = itk::Image<RGBPixelType, Dimension>;
|
||||
|
||||
using ReaderType = itk::ImageFileReader<RGBImageType>;
|
||||
|
||||
ReaderType::Pointer actualImageReader;
|
||||
ReaderType::Pointer expectedImageReader;
|
||||
};
|
||||
|
||||
#endif // hifi_ITKImageComparer_h
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
class ImageComparer {
|
||||
public:
|
||||
virtual float compareImages(QString file1, QString file2) const = 0;
|
||||
virtual float compareImages(QString actualImageFilename, QString expectedImageFilename) const = 0;
|
||||
};
|
||||
|
||||
#endif // hifi_ImageComparer_h
|
||||
|
|
|
@ -57,10 +57,10 @@ void Test::evaluateTests() {
|
|||
}
|
||||
|
||||
// The number of images in each list should be identical
|
||||
if (expectedImages.length() != resultImages.length()) {
|
||||
if (expectedImages.length() != actualImages.length()) {
|
||||
messageBox.critical(0,
|
||||
"Test failed",
|
||||
"Found " + QString::number(resultImages.length()) + " images in directory" +
|
||||
"Found " + QString::number(actualImages.length()) + " images in directory" +
|
||||
"\nExpected to find " + QString::number(expectedImages.length()) + " images");
|
||||
|
||||
exit(-1);
|
||||
|
@ -72,7 +72,7 @@ void Test::evaluateTests() {
|
|||
bool success{ true };
|
||||
bool keepOn{ true };
|
||||
for (int i = 0; keepOn && i < expectedImages.length(); ++i) {
|
||||
float error = itkImageComparer.compareImages(expectedImages[i], actualImages[i]);
|
||||
float error = itkImageComparer.compareImages(actualImages[i], expectedImages[i]);
|
||||
if (error > THRESHOLD) {
|
||||
mismatchWindow.setTestFailure(TestFailure{
|
||||
error, // value of the error (float)
|
||||
|
|
Loading…
Reference in a new issue