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 cv::RNG &rng = TS::ptr()->get_rng();
95 roicols = rng.uniform(2, mat1.cols);
96 roirows = rng.uniform(2, mat1.rows);
97 src1x = rng.uniform(0, mat1.cols - roicols);
98 src1y = rng.uniform(0, mat1.rows - roirows);
99 dstx = rng.uniform(0, dst.cols - roicols);
100 dsty = rng.uniform(0, dst.rows - roirows);
110 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
111 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
114 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
119 void Init(int mat_type)
121 cv::Size size(MWIDTH, MHEIGHT);
122 mat1 = randomMat(size, mat_type, 5, 16);
123 dst = randomMat(size, mat_type, 5, 16);
126 void Near(double threshold)
128 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), threshold);
132 /////////////////////////////////////////////////////////////////////////////////////////////////
134 struct Blur : FilterTestBase
143 ksize = GET_PARAM(1);
144 bordertype = GET_PARAM(3);
151 for(int j = 0; j < LOOP_TIMES; j++)
154 cv::blur(mat1_roi, dst_roi, ksize, Point(-1, -1), bordertype);
155 cv::ocl::blur(gmat1, gdst, ksize, Point(-1, -1), bordertype);
161 /////////////////////////////////////////////////////////////////////////////////////////////////
163 struct Laplacian : FilterTestBase
171 ksize = GET_PARAM(1);
176 TEST_P(Laplacian, Accuracy)
178 for(int j = 0; j < LOOP_TIMES; j++)
181 cv::Laplacian(mat1_roi, dst_roi, -1, ksize.width, 1);
182 cv::ocl::Laplacian(gmat1, gdst, -1, ksize.width, 1);
189 /////////////////////////////////////////////////////////////////////////////////////////////////
191 struct ErodeDilate : FilterTestBase
196 //erode or dilate kernel
202 iterations = GET_PARAM(3);
204 // rng.fill(kernel, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
205 kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
210 TEST_P(ErodeDilate, Mat)
212 for(int j = 0; j < LOOP_TIMES; j++)
215 cv::erode(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
216 cv::ocl::erode(gmat1, gdst, kernel, Point(-1, -1), iterations);
219 for(int j = 0; j < LOOP_TIMES; j++)
222 cv::dilate(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
223 cv::ocl::dilate(gmat1, gdst, kernel, Point(-1, -1), iterations);
229 /////////////////////////////////////////////////////////////////////////////////////////////////
231 struct Sobel : FilterTestBase
234 int dx, dy, ksize, bordertype;
239 Size s = GET_PARAM(1);
244 bordertype = GET_PARAM(3);
251 for(int j = 0; j < LOOP_TIMES; j++)
254 cv::Sobel(mat1_roi, dst_roi, -1, dx, dy, ksize, /*scale*/0.00001,/*delta*/0, bordertype);
255 cv::ocl::Sobel(gmat1, gdst, -1, dx, dy, ksize,/*scale*/0.00001,/*delta*/0, bordertype);
261 /////////////////////////////////////////////////////////////////////////////////////////////////
263 struct Scharr : FilterTestBase
266 int dx, dy, bordertype;
271 Size s = GET_PARAM(2);
274 bordertype = GET_PARAM(3);
281 for(int j = 0; j < LOOP_TIMES; j++)
284 cv::Scharr(mat1_roi, dst_roi, -1, dx, dy, /*scale*/1,/*delta*/0, bordertype);
285 cv::ocl::Scharr(gmat1, gdst, -1, dx, dy,/*scale*/1,/*delta*/0, bordertype);
292 /////////////////////////////////////////////////////////////////////////////////////////////////
294 struct GaussianBlur : FilterTestBase
299 double sigma1, sigma2;
304 ksize = GET_PARAM(1);
305 bordertype = GET_PARAM(3);
307 cv::RNG &rng = TS::ptr()->get_rng();
308 sigma1 = rng.uniform(0.1, 1.0);
309 sigma2 = rng.uniform(0.1, 1.0);
313 TEST_P(GaussianBlur, Mat)
315 for(int j = 0; j < LOOP_TIMES; j++)
318 cv::GaussianBlur(mat1_roi, dst_roi, ksize, sigma1, sigma2, bordertype);
319 cv::ocl::GaussianBlur(gmat1, gdst, ksize, sigma1, sigma2, bordertype);
327 ////////////////////////////////////////////////////////////////////////////////////////////////////
329 struct Filter2D : FilterTestBase
338 ksize = GET_PARAM(1);
339 bordertype = GET_PARAM(3);
341 anchor = Point(-1,-1);
345 TEST_P(Filter2D, Mat)
347 cv::Mat kernel = randomMat(cv::Size(ksize.width, ksize.height), CV_32FC1, 0.0, 1.0);
348 for(int j = 0; j < LOOP_TIMES; j++)
351 cv::filter2D(mat1_roi, dst_roi, -1, kernel, anchor, 0.0, bordertype);
352 cv::ocl::filter2D(gmat1, gdst, -1, kernel, anchor, bordertype);
356 ////////////////////////////////////////////////////////////////////////////////////////////////////
358 struct Bilateral : FilterTestBase
363 double sigmacolor, sigmaspace;
368 ksize = GET_PARAM(1);
369 bordertype = GET_PARAM(3);
371 cv::RNG &rng = TS::ptr()->get_rng();
372 sigmacolor = rng.uniform(20, 100);
373 sigmaspace = rng.uniform(10, 40);
377 TEST_P(Bilateral, Mat)
379 for(int j = 0; j < LOOP_TIMES; j++)
382 cv::bilateralFilter(mat1_roi, dst_roi, ksize.width, sigmacolor, sigmaspace, bordertype);
383 cv::ocl::bilateralFilter(gmat1, gdst, ksize.width, sigmacolor, sigmaspace, bordertype);
389 ////////////////////////////////////////////////////////////////////////////////////////////////////
391 struct AdaptiveBilateral : FilterTestBase
400 ksize = GET_PARAM(1);
401 bordertype = GET_PARAM(3);
403 anchor = Point(-1,-1);
407 TEST_P(AdaptiveBilateral, Mat)
409 for(int j = 0; j < LOOP_TIMES; j++)
412 cv::adaptiveBilateralFilter(mat1_roi, dst_roi, ksize, 5, anchor, bordertype);
413 cv::ocl::adaptiveBilateralFilter(gmat1, gdst, ksize, 5, anchor, bordertype);
419 INSTANTIATE_TEST_CASE_P(Filter, Blur, Combine(
420 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
421 Values(cv::Size(3, 3), cv::Size(5, 5), cv::Size(7, 7)),
422 Values(Size(0, 0)), //not use
423 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101)));
426 INSTANTIATE_TEST_CASE_P(Filter, Laplacian, Combine(
427 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
429 Values(Size(0, 0)), //not use
430 Values(0))); //not use
432 INSTANTIATE_TEST_CASE_P(Filter, ErodeDilate, Combine(
433 Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
434 Values(Size(0, 0)), //not use
435 Values(Size(0, 0)), //not use
439 INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine(
440 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
441 Values(Size(3, 3), Size(5, 5)),
442 Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)),
443 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
446 INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine(
447 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
448 Values(Size(0, 0)), //not use
449 Values(Size(0, 1), Size(1, 0)),
450 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
452 INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine(
453 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
454 Values(Size(3, 3), Size(5, 5)),
455 Values(Size(0, 0)), //not use
456 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
460 INSTANTIATE_TEST_CASE_P(Filter, Filter2D, testing::Combine(
461 Values(CV_8UC1, CV_32FC1, CV_32FC4),
462 Values(Size(3, 3), Size(15, 15), Size(25, 25)),
463 Values(Size(0, 0)), //not use
464 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REFLECT101, (MatType)cv::BORDER_REPLICATE, (MatType)cv::BORDER_REFLECT)));
466 INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine(
467 Values(CV_8UC1, CV_8UC3),
468 Values(Size(5, 5), Size(9, 9)),
469 Values(Size(0, 0)), //not use
470 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE,
471 (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_WRAP, (MatType)cv::BORDER_REFLECT_101)));
473 INSTANTIATE_TEST_CASE_P(Filter, AdaptiveBilateral, Combine(
474 Values(CV_8UC1, CV_8UC3),
475 Values(Size(5, 5), Size(9, 9)),
476 Values(Size(0, 0)), //not use
477 Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE,
478 (MatType)cv::BORDER_REFLECT, (MatType)cv::BORDER_REFLECT_101)));
479 #endif // HAVE_OPENCL