MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkConvertGrayscaleOpenCVImageFilterTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <mitkTestingMacros.h>
15
16#include <opencv2/imgproc.hpp>
17#include <opencv2/imgproc/imgproc_c.h>
18#include <opencv2/imgcodecs.hpp>
19
20static void ConvertTestLoadedImage(std::string mitkImagePath, std::string mitkGrayscaleImagePath)
21{
22 cv::Mat image = cv::imread(mitkImagePath.c_str());
23 cv::Mat compareImg = cv::imread(mitkGrayscaleImagePath.c_str());
24
25 // directly convert the image for comparison
26 cv::Mat comparisonImg;
27 cv::cvtColor(compareImg, comparisonImg, CV_RGB2GRAY, 1);
28
29 mitk::ConvertGrayscaleOpenCVImageFilter::Pointer grayscaleFilter
30 = mitk::ConvertGrayscaleOpenCVImageFilter::New();
31
32 MITK_TEST_CONDITION(grayscaleFilter->FilterImage(image), "Filtering should return true for success.");
33
34 MITK_TEST_CONDITION(image.channels() == 1, "Image must not have more than one channel after grayscale conversion.");
35
36 MITK_TEST_CONDITION(cv::countNonZero(image != comparisonImg) == 0, "All pixel values must be the same between the two converted images.");
37
38 MITK_TEST_CONDITION_REQUIRED(grayscaleFilter->FilterImage(image), "Image conversion should be no problem if image is a grayscale image already.")
39}
40
45{
46 MITK_TEST_BEGIN("ConvertGrayscaleOpenCVImageFilter")
47
48 MITK_TEST_CONDITION_REQUIRED(argc > 2, "At least three parameters needed for this test.")
49
50 ConvertTestLoadedImage(argv[1], argv[2]);
51
52 MITK_TEST_END(); // always end with this!
53
54}
int mitkConvertGrayscaleOpenCVImageFilterTest(int argc, char *argv[])