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
5 // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
6 // Third party copyrights are property of their respective owners.
7
8 #include "../test_precomp.hpp"
9 #include "opencv2/ts/ocl_test.hpp"
10
11 #ifdef HAVE_OPENCL
12
13 namespace cvtest {
14 namespace ocl {
15
PARAM_TEST_CASE(FastNlMeansDenoisingTestBase,Channels,int,bool,bool)16 PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, int, bool, bool)
17 {
18 int cn, normType, templateWindowSize, searchWindowSize;
19 std::vector<float> h;
20 bool use_roi, use_image;
21
22 TEST_DECLARE_INPUT_PARAMETER(src);
23 TEST_DECLARE_OUTPUT_PARAMETER(dst);
24
25 virtual void SetUp()
26 {
27 cn = GET_PARAM(0);
28 normType = GET_PARAM(1);
29 use_roi = GET_PARAM(2);
30 use_image = GET_PARAM(3);
31
32 templateWindowSize = 7;
33 searchWindowSize = 21;
34
35 h.resize(cn);
36 for (int i=0; i<cn; i++)
37 h[i] = 3.0f + 0.5f*i;
38 }
39
40 virtual void generateTestData()
41 {
42 const int type = CV_8UC(cn);
43 Mat image;
44
45 if (use_image) {
46 image = readImage("denoising/lena_noised_gaussian_sigma=10.png",
47 cn == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
48 ASSERT_FALSE(image.empty());
49 }
50
51 Size roiSize = use_image ? image.size() : randomSize(1, MAX_VALUE);
52 Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
53 randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255);
54 if (use_image) {
55 ASSERT_TRUE(cn > 0 && cn <= 4);
56 if (cn == 2) {
57 int from_to[] = { 0,0, 1,1 };
58 src_roi.create(roiSize, type);
59 mixChannels(&image, 1, &src_roi, 1, from_to, 2);
60 }
61 else if (cn == 4) {
62 int from_to[] = { 0,0, 1,1, 2,2, 1,3};
63 src_roi.create(roiSize, type);
64 mixChannels(&image, 1, &src_roi, 1, from_to, 4);
65 }
66 else image.copyTo(src_roi);
67 }
68
69 Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
70 randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255);
71
72 UMAT_UPLOAD_INPUT_PARAMETER(src);
73 UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
74 }
75 };
76
77 typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising;
78
OCL_TEST_P(FastNlMeansDenoising,Mat)79 OCL_TEST_P(FastNlMeansDenoising, Mat)
80 {
81 for (int j = 0; j < test_loop_times; j++)
82 {
83 generateTestData();
84
85 OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
86 OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
87
88 OCL_EXPECT_MATS_NEAR(dst, 1);
89 }
90 }
91
92 typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising_hsep;
93
OCL_TEST_P(FastNlMeansDenoising_hsep,Mat)94 OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)
95 {
96 for (int j = 0; j < test_loop_times; j++)
97 {
98 generateTestData();
99
100 OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize, normType));
101 OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize, normType));
102
103 OCL_EXPECT_MATS_NEAR(dst, 1);
104 }
105 }
106
107 typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored;
108
OCL_TEST_P(FastNlMeansDenoisingColored,Mat)109 OCL_TEST_P(FastNlMeansDenoisingColored, Mat)
110 {
111 for (int j = 0; j < test_loop_times; j++)
112 {
113 generateTestData();
114
115 OCL_OFF(cv::fastNlMeansDenoisingColored(src_roi, dst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
116 OCL_ON(cv::fastNlMeansDenoisingColored(usrc_roi, udst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
117
118 OCL_EXPECT_MATS_NEAR(dst, 1);
119 }
120 }
121
122 OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising,
123 Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
124 Bool(), Values(true)));
125 OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising_hsep,
126 Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
127 Bool(), Values(true)));
128 OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored,
129 Combine(Values(3, 4), Values((int)NORM_L2), Bool(), Values(false)));
130
131 } } // namespace cvtest::ocl
132
133 #endif // HAVE_OPENCL
134