14#include <mitkTestingMacros.h>
16#include <opencv2/imgproc.hpp>
17#include <opencv2/imgproc/imgproc_c.h>
18#include <opencv2/imgcodecs.hpp>
20static void ConvertTestLoadedImage(std::string mitkImagePath, std::string mitkGrayscaleImagePath)
22 cv::Mat image = cv::imread(mitkImagePath.c_str());
23 cv::Mat compareImg = cv::imread(mitkGrayscaleImagePath.c_str());
26 cv::Mat comparisonImg;
27 cv::cvtColor(compareImg, comparisonImg, CV_RGB2GRAY, 1);
29 mitk::ConvertGrayscaleOpenCVImageFilter::Pointer grayscaleFilter
30 = mitk::ConvertGrayscaleOpenCVImageFilter::New();
32 MITK_TEST_CONDITION(grayscaleFilter->FilterImage(image),
"Filtering should return true for success.");
34 MITK_TEST_CONDITION(image.channels() == 1,
"Image must not have more than one channel after grayscale conversion.");
36 MITK_TEST_CONDITION(cv::countNonZero(image != comparisonImg) == 0,
"All pixel values must be the same between the two converted images.");
38 MITK_TEST_CONDITION_REQUIRED(grayscaleFilter->FilterImage(image),
"Image conversion should be no problem if image is a grayscale image already.")
46 MITK_TEST_BEGIN(
"ConvertGrayscaleOpenCVImageFilter")
48 MITK_TEST_CONDITION_REQUIRED(argc > 2,
"At least three parameters needed for this test.")
50 ConvertTestLoadedImage(argv[1], argv[2]);
int mitkConvertGrayscaleOpenCVImageFilterTest(int argc, char *argv[])