1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
19 // Niko Li, newlife20080214@gmail.com
20 // Jia Haipeng, jiahaipeng95@gmail.com
21 // Zero Lin, Zero.Lin@amd.com
22 // Zhang Ying, zhangying913@gmail.com
23 // Yao Wang, bitwangyaoyao@gmail.com
25 // Redistribution and use in source and binary forms, with or without modification,
26 // are permitted provided that the following conditions are met:
28 // * Redistribution's of source code must retain the above copyright notice,
29 // this list of conditions and the following disclaimer.
31 // * Redistribution's in binary form must reproduce the above copyright notice,
32 // this list of conditions and the following disclaimer in the documentation
33 // and/or other oclMaterials provided with the distribution.
35 // * The name of the copyright holders may not be used to endorse or promote products
36 // derived from this software without specific prior written permission.
38 // This software is provided by the copyright holders and contributors "as is" and
39 // any express or implied warranties, including, but not limited to, the implied
40 // warranties of merchantability and fitness for a particular purpose are disclaimed.
41 // In no event shall the Intel Corporation or contributors be liable for any direct,
42 // indirect, incidental, special, exemplary, or consequential damages
43 // (including, but not limited to, procurement of substitute goods or services;
44 // loss of use, data, or profits; or business interruption) however caused
45 // and on any theory of liability, whether in contract, strict liability,
46 // or tort (including negligence or otherwise) arising in any way out of
47 // the use of this software, even if advised of the possibility of such damage.
51 #include "test_precomp.hpp"
55 using namespace cvtest;
56 using namespace testing;
60 PARAM_TEST_CASE(FilterTestBase,
62 cv::Size, // kernel size
64 int // border type, or iteration
83 //ocl dst mat for testing
84 cv::ocl::oclMat gdst_whole;
87 cv::ocl::oclMat gmat1;
94 roicols = rng.uniform(2, mat1.cols);
95 roirows = rng.uniform(2, mat1.rows);
96 src1x = rng.uniform(0, mat1.cols - roicols);
97 src1y = rng.uniform(0, mat1.rows - roirows);
98 dstx = rng.uniform(0, dst.cols - roicols);
99 dsty = rng.uniform(0, dst.rows - roirows);
109 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
110 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
113 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
118 void Init(int mat_type)
120 cv::Size size(MWIDTH, MHEIGHT);
121 mat1 = randomMat(size, mat_type, 5, 16);
122 dst = randomMat(size, mat_type, 5, 16);
125 void Near(double threshold)
127 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), threshold);
131 /////////////////////////////////////////////////////////////////////////////////////////////////
133 struct Blur : FilterTestBase
142 ksize = GET_PARAM(1);
143 bordertype = GET_PARAM(3);
150 for(int j = 0; j < LOOP_TIMES; j++)
153 cv::blur(mat1_roi, dst_roi, ksize, Point(-1, -1), bordertype);
154 cv::ocl::blur(gmat1, gdst, ksize, Point(-1, -1), bordertype);
160 /////////////////////////////////////////////////////////////////////////////////////////////////
162 struct Laplacian : FilterTestBase
170 ksize = GET_PARAM(1);
175 TEST_P(Laplacian, Accuracy)
177 for(int j = 0; j < LOOP_TIMES; j++)
180 cv::Laplacian(mat1_roi, dst_roi, -1, ksize.width, 1);
181 cv::ocl::Laplacian(gmat1, gdst, -1, ksize.width, 1);
188 /////////////////////////////////////////////////////////////////////////////////////////////////
190 struct ErodeDilate : FilterTestBase
195 //erode or dilate kernel
201 iterations = GET_PARAM(3);
203 kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
208 TEST_P(ErodeDilate, Mat)
210 for(int j = 0; j < LOOP_TIMES; j++)
213 cv::erode(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
214 cv::ocl::erode(gmat1, gdst, kernel, Point(-1, -1), iterations);
217 for(int j = 0; j < LOOP_TIMES; j++)
220 cv::dilate(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
221 cv::ocl::dilate(gmat1, gdst, kernel, Point(-1, -1), iterations);
227 /////////////////////////////////////////////////////////////////////////////////////////////////
229 struct Sobel : FilterTestBase
232 int dx, dy, ksize, bordertype;
237 Size s = GET_PARAM(1);
242 bordertype = GET_PARAM(3);
249 for(int j = 0; j < LOOP_TIMES; j++)
252 cv::Sobel(mat1_roi, dst_roi, -1, dx, dy, ksize, /*scale*/0.00001,/*delta*/0, bordertype);
253 cv::ocl::Sobel(gmat1, gdst, -1, dx, dy, ksize,/*scale*/0.00001,/*delta*/0, bordertype);
259 /////////////////////////////////////////////////////////////////////////////////////////////////
261 struct Scharr : FilterTestBase
264 int dx, dy, bordertype;
269 Size s = GET_PARAM(2);
272 bordertype = GET_PARAM(3);
279 for(int j = 0; j < LOOP_TIMES; j++)
282 cv::Scharr(mat1_roi, dst_roi, -1, dx, dy, /*scale*/1,/*delta*/0, bordertype);
283 cv::ocl::Scharr(gmat1, gdst, -1, dx, dy,/*scale*/1,/*delta*/0, bordertype);
290 /////////////////////////////////////////////////////////////////////////////////////////////////
292 struct GaussianBlur : FilterTestBase
297 double sigma1, sigma2;
302 ksize = GET_PARAM(1);
303 bordertype = GET_PARAM(3);
305 sigma1 = rng.uniform(0.1, 1.0);
306 sigma2 = rng.uniform(0.1, 1.0);
310 TEST_P(GaussianBlur, Mat)
312 for(int j = 0; j < LOOP_TIMES; j++)
315 cv::GaussianBlur(mat1_roi, dst_roi, ksize, sigma1, sigma2, bordertype);
316 cv::ocl::GaussianBlur(gmat1, gdst, ksize, sigma1, sigma2, bordertype);
324 ////////////////////////////////////////////////////////////////////////////////////////////////////
326 struct Filter2D : FilterTestBase
335 ksize = GET_PARAM(1);
336 bordertype = GET_PARAM(3);
338 anchor = Point(-1,-1);
342 TEST_P(Filter2D, Mat)
344 cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
345 for(int j = 0; j < LOOP_TIMES; j++)
348 cv::filter2D(mat1_roi, dst_roi, -1, kernel, anchor, 0.0, bordertype);
349 cv::ocl::filter2D(gmat1, gdst, -1, kernel, anchor, bordertype);
353 ////////////////////////////////////////////////////////////////////////////////////////////////////
355 struct Bilateral : FilterTestBase
360 double sigmacolor, sigmaspace;
365 ksize = GET_PARAM(1);
366 bordertype = GET_PARAM(3);
368 sigmacolor = rng.uniform(20, 100);
369 sigmaspace = rng.uniform(10, 40);
373 TEST_P(Bilateral, Mat)
375 for(int j = 0; j < LOOP_TIMES; j++)
378 cv::bilateralFilter(mat1_roi, dst_roi, ksize.width, sigmacolor, sigmaspace, bordertype);
379 cv::ocl::bilateralFilter(gmat1, gdst, ksize.width, sigmacolor, sigmaspace, bordertype);
385 ////////////////////////////////////////////////////////////////////////////////////////////////////
387 struct AdaptiveBilateral : FilterTestBase
396 ksize = GET_PARAM(1);
397 bordertype = GET_PARAM(3);
399 anchor = Point(-1,-1);
403 TEST_P(AdaptiveBilateral, Mat)
405 for(int j = 0; j < LOOP_TIMES; j++)
408 cv::adaptiveBilateralFilter(mat1_roi, dst_roi, ksize, 5, anchor, bordertype);
409 cv::ocl::adaptiveBilateralFilter(gmat1, gdst, ksize, 5, anchor, bordertype);
415 INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine(
416 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
417 Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)),
418 Values(Size(0, 0)), //not use
419 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101)));
422 INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine(
423 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
425 Values(Size(0, 0)), //not use
426 Values(0))); //not use
428 INSTANTIATE_TEST_CASE_P(Filter, ErodeDilate, Combine(
429 Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
430 Values(Size(0, 0)), //not use
431 Values(Size(0, 0)), //not use
435 INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine(
436 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
437 Values(Size(3, 3), Size(5, 5)),
438 Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)),
439 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
442 INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine(
443 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
444 Values(Size(0, 0)), //not use
445 Values(Size(0, 1), Size(1, 0)),
446 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
448 INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine(
449 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
450 Values(Size(3, 3), Size(5, 5)),
451 Values(Size(0, 0)), //not use
452 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
456 INSTANTIATE_TEST_CASE_P(Filter, Filter2D, testing::Combine(
457 Values(CV_8UC1, CV_32FC1, CV_32FC4),
458 Values(Size(3, 3), Size(15, 15), Size(25, 25)),
459 Values(Size(0, 0)), //not use
460 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REFLECT101, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT)));
462 INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine(
463 Values(CV_8UC1, CV_8UC3),
464 Values(Size(5, 5), Size(9, 9)),
465 Values(Size(0, 0)), //not use
466 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE,
467 (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_WRAP, (MatType)cv::BORDER_REFLECT_101)));
469 INSTANTIATE_TEST_CASE_P(Filter, AdaptiveBilateral, Combine(
470 Values(CV_8UC1, CV_8UC3),
471 Values(Size(5, 5), Size(9, 9)),
472 Values(Size(0, 0)), //not use
473 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE,
474 (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101)));
475 #endif // HAVE_OPENCL