test_denoising.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "../test_precomp.hpp"
  7. #include "opencv2/ts/ocl_test.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, int, bool, bool)
  12. {
  13. int cn, normType, templateWindowSize, searchWindowSize;
  14. std::vector<float> h;
  15. bool use_roi, use_image;
  16. TEST_DECLARE_INPUT_PARAMETER(src);
  17. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  18. virtual void SetUp()
  19. {
  20. cn = GET_PARAM(0);
  21. normType = GET_PARAM(1);
  22. use_roi = GET_PARAM(2);
  23. use_image = GET_PARAM(3);
  24. templateWindowSize = 7;
  25. searchWindowSize = 21;
  26. h.resize(cn);
  27. for (int i=0; i<cn; i++)
  28. h[i] = 3.0f + 0.5f*i;
  29. }
  30. void generateTestData()
  31. {
  32. const int type = CV_8UC(cn);
  33. Mat image;
  34. if (use_image) {
  35. image = readImage("denoising/lena_noised_gaussian_sigma=10.png",
  36. cn == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
  37. ASSERT_FALSE(image.empty());
  38. }
  39. Size roiSize = use_image ? image.size() : randomSize(1, MAX_VALUE);
  40. Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  41. randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255);
  42. if (use_image) {
  43. ASSERT_TRUE(cn > 0 && cn <= 4);
  44. if (cn == 2) {
  45. int from_to[] = { 0,0, 1,1 };
  46. src_roi.create(roiSize, type);
  47. mixChannels(&image, 1, &src_roi, 1, from_to, 2);
  48. }
  49. else if (cn == 4) {
  50. int from_to[] = { 0,0, 1,1, 2,2, 1,3};
  51. src_roi.create(roiSize, type);
  52. mixChannels(&image, 1, &src_roi, 1, from_to, 4);
  53. }
  54. else image.copyTo(src_roi);
  55. }
  56. Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  57. randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255);
  58. UMAT_UPLOAD_INPUT_PARAMETER(src);
  59. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  60. }
  61. };
  62. typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising;
  63. OCL_TEST_P(FastNlMeansDenoising, Mat)
  64. {
  65. for (int j = 0; j < test_loop_times; j++)
  66. {
  67. generateTestData();
  68. OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
  69. OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
  70. OCL_EXPECT_MATS_NEAR(dst, 1);
  71. }
  72. }
  73. typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising_hsep;
  74. OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)
  75. {
  76. for (int j = 0; j < test_loop_times; j++)
  77. {
  78. generateTestData();
  79. OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize, normType));
  80. OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize, normType));
  81. OCL_EXPECT_MATS_NEAR(dst, 1);
  82. }
  83. }
  84. typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored;
  85. OCL_TEST_P(FastNlMeansDenoisingColored, Mat)
  86. {
  87. for (int j = 0; j < test_loop_times; j++)
  88. {
  89. generateTestData();
  90. OCL_OFF(cv::fastNlMeansDenoisingColored(src_roi, dst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
  91. OCL_ON(cv::fastNlMeansDenoisingColored(usrc_roi, udst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
  92. OCL_EXPECT_MATS_NEAR(dst, 1);
  93. }
  94. }
  95. OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising,
  96. Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
  97. Bool(), Values(true)));
  98. OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising_hsep,
  99. Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
  100. Bool(), Values(true)));
  101. OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored,
  102. Combine(Values(3, 4), Values((int)NORM_L2), Bool(), Values(false)));
  103. } } // namespace opencv_test::ocl
  104. #endif // HAVE_OPENCL