diff --git a/Modules/OpenCVVideoSupport/Testing/CMakeLists.txt b/Modules/OpenCVVideoSupport/Testing/CMakeLists.txt index 8d43ce4a4d..21826cc97f 100644 --- a/Modules/OpenCVVideoSupport/Testing/CMakeLists.txt +++ b/Modules/OpenCVVideoSupport/Testing/CMakeLists.txt @@ -1,10 +1,18 @@ MITK_CREATE_MODULE_TESTS() IF(BUILD_TESTING AND MODULE_IS_ENABLED) mitkAddCustomModuleTest("mitkOpenCVMitkConversionTest" "mitkOpenCVMitkConversionTest" "${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom_DistanceImage.nrrd" "${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom_RGBImage.nrrd" "${MITK_DATA_DIR}/Png2D-bw.png" "${MITK_DATA_DIR}/NrrdWritingTestImage.jpg" ) -ENDIF(BUILD_TESTING AND MODULE_IS_ENABLED) \ No newline at end of file + mitkAddCustomModuleTest("mitkCropOpenCVImageFilterTest" "mitkCropOpenCVImageFilterTest" + "${MITK_DATA_DIR}/OpenCV-Data/BaseImage.png" + "${MITK_DATA_DIR}/OpenCV-Data/CroppedImage.png" + ) + mitkAddCustomModuleTest("mitkConvertGrayscaleOpenCVImageFilterTest" "mitkConvertGrayscaleOpenCVImageFilterTest" + "${MITK_DATA_DIR}/OpenCV-Data/BaseImage.png" + "${MITK_DATA_DIR}/OpenCV-Data/GrayscaleImage.png" + ) +ENDIF(BUILD_TESTING AND MODULE_IS_ENABLED) diff --git a/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp index 42c5afb03c..bcea7a2908 100644 --- a/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp +++ b/Modules/OpenCVVideoSupport/Testing/mitkConvertGrayscaleOpenCVImageFilterTest.cpp @@ -1,52 +1,55 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkConvertGrayscaleOpenCVImageFilter.h" #include #include #include -static void ConvertTestLoadedImage(std::string mitkImagePath) +static void ConvertTestLoadedImage(std::string mitkImagePath, std::string mitkGrayscaleImagePath) { cv::Mat image = cvLoadImage(mitkImagePath.c_str()); + cv::Mat compareImg = cvLoadImage(mitkGrayscaleImagePath.c_str()); // directly convert the image for comparison cv::Mat comparisonImg; - cv::cvtColor(image, comparisonImg, CV_RGB2GRAY, 1); + cv::cvtColor(compareImg, comparisonImg, CV_RGB2GRAY, 1); mitk::ConvertGrayscaleOpenCVImageFilter::Pointer grayscaleFilter = mitk::ConvertGrayscaleOpenCVImageFilter::New(); - MITK_TEST_CONDITION_REQUIRED(grayscaleFilter->FilterImage(image), "Filtering should return true for success."); + MITK_TEST_CONDITION(grayscaleFilter->FilterImage(image), "Filtering should return true for success."); - MITK_TEST_CONDITION_REQUIRED(image.channels() == 1, "Image must not have more than one channel after grayscale conversion."); + MITK_TEST_CONDITION(image.channels() == 1, "Image must not have more than one channel after grayscale conversion."); - MITK_TEST_CONDITION_REQUIRED(cv::countNonZero(image != comparisonImg) == 0, "All pixel values must be the same between the two converted images."); + MITK_TEST_CONDITION(cv::countNonZero(image != comparisonImg) == 0, "All pixel values must be the same between the two converted images."); } /**Documentation * test for the class "ConvertGrayscaleOpenCVImageFilter". */ int mitkConvertGrayscaleOpenCVImageFilterTest(int argc, char* argv[]) { MITK_TEST_BEGIN("ConvertGrayscaleOpenCVImageFilter") - ConvertTestLoadedImage(argv[1]); - // always end with this! - MITK_TEST_END(); + MITK_TEST_CONDITION_REQUIRED(argc > 2, "At least three parameters needed for this test.") + + ConvertTestLoadedImage(argv[1], argv[2]); + + MITK_TEST_END(); // always end with this! } diff --git a/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp index 197c49c320..54a5079e8b 100644 --- a/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp +++ b/Modules/OpenCVVideoSupport/Testing/mitkCropOpenCVImageFilterTest.cpp @@ -1,80 +1,87 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkCropOpenCVImageFilter.h" #include #include #include static bool ImagesAreEqualInGray(const cv::Mat& img1, const cv::Mat& img2) { cv::Mat grayImg1; cv::Mat grayImg2; cv::cvtColor(img1, grayImg1, CV_RGB2GRAY, 1); cv::cvtColor(img2, grayImg2, CV_RGB2GRAY, 1); return cv::countNonZero(grayImg1 != grayImg2) == 0; } -static void CropTestLoadedImage(std::string mitkImagePath) +static void CropTestLoadedImage(std::string mitkImagePath, std::string mitkCroppedImagePath) { cv::Mat image = cvLoadImage(mitkImagePath.c_str()); - cv::Mat compareImg = image.clone(); + cv::Mat croppedImage = cvLoadImage(mitkCroppedImagePath.c_str()); + + MITK_INFO << mitkImagePath.c_str(); + MITK_INFO << mitkCroppedImagePath.c_str(); mitk::CropOpenCVImageFilter::Pointer cropFilter = mitk::CropOpenCVImageFilter::New(); // try to crop without setting a region of interest - MITK_TEST_CONDITION_REQUIRED( ! cropFilter->FilterImage(image), "Filter function must return false if no region of interest is set."); - MITK_TEST_CONDITION_REQUIRED(ImagesAreEqualInGray(image, compareImg), "Image should not be changed yet."); + cv::Mat testImage = image.clone(); + MITK_TEST_CONDITION( ! cropFilter->FilterImage(testImage), "Filter function must return false if no region of interest is set."); + MITK_TEST_CONDITION(ImagesAreEqualInGray(testImage, image), "Image should not be changed yet."); // set region of interst now and then try to crop again - cv::Rect roi = cv::Rect(0,0, image.cols, image.rows); + cv::Rect roi = cv::Rect(0,0, testImage.cols, testImage.rows); cropFilter->SetCropRegion(roi); - MITK_TEST_CONDITION_REQUIRED(cropFilter->FilterImage(image), "Filter function should return successfully."); - MITK_TEST_CONDITION_REQUIRED(ImagesAreEqualInGray(image, compareImg), "Image should not be changed if cropping with a roi of the whole image."); + MITK_TEST_CONDITION(cropFilter->FilterImage(testImage), "Filter function should return successfully."); + MITK_TEST_CONDITION(ImagesAreEqualInGray(testImage, image), "Image should not be changed if cropping with a roi of the whole image."); // test if filter corrects negative roi position cv::Rect roiWrong = cv::Rect(-1,-1, 2, 2); roi = cv::Rect(0,0,2,2); cropFilter->SetCropRegion(roiWrong); - MITK_TEST_CONDITION_REQUIRED(cropFilter->FilterImage(image), "Filter function should return successfully."); - MITK_TEST_CONDITION_REQUIRED(ImagesAreEqualInGray(image, compareImg(roi)), "Image should be equal to directly cropped image whith correct roi."); + MITK_TEST_CONDITION(cropFilter->FilterImage(testImage), "Filter function should return successfully."); + MITK_TEST_CONDITION(ImagesAreEqualInGray(testImage, image(roi)), "Image should be equal to directly cropped image whith correct roi."); // test whith "normal" roi - //roi = cv::Rect( 5,5,10,10 ); + testImage = image.clone(); + roi = cv::Rect( 150,100,100,100 ); cropFilter->SetCropRegion(roi); - MITK_TEST_CONDITION_REQUIRED(cropFilter->FilterImage(image), "Filter function should return successfully."); - MITK_TEST_CONDITION_REQUIRED(ImagesAreEqualInGray(image, compareImg(roi)), "Image should be equal to directly cropped image."); + MITK_TEST_CONDITION(cropFilter->FilterImage(testImage), "Filter function should return successfully."); + MITK_TEST_CONDITION(ImagesAreEqualInGray(testImage, croppedImage), "Image should be equal to cropped image (loaded from data directory)."); // test with not correctable roi roiWrong = cv::Rect( 5,5,-1,-1 ); MITK_TEST_FOR_EXCEPTION(mitk::Exception, cropFilter->SetCropRegion(roiWrong)); } /**Documentation * test for the class "CropOpenCVImageFilter". */ int mitkCropOpenCVImageFilterTest(int argc, char* argv[]) { MITK_TEST_BEGIN("CropOpenCVImageFilter") - CropTestLoadedImage(argv[1]); - // always end with this! - MITK_TEST_END(); + MITK_TEST_CONDITION_REQUIRED(argc > 2, "At least three parameters needed for this test."); + + CropTestLoadedImage(argv[1], argv[2]); + + MITK_TEST_END(); // always end with this! }