2014-02-20 20:05:50 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
|
|
|
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
2014-02-17 01:54:51 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
|
2014-08-01 22:11:20 +08:00
|
|
|
#include "../test_precomp.hpp"
|
2014-02-17 01:54:51 +08:00
|
|
|
#include "opencv2/ts/ocl_test.hpp"
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
|
|
|
|
namespace cvtest {
|
|
|
|
namespace ocl {
|
|
|
|
|
2015-03-02 05:22:09 +08:00
|
|
|
PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, bool, bool)
|
2014-02-17 01:54:51 +08:00
|
|
|
{
|
|
|
|
int cn, templateWindowSize, searchWindowSize;
|
2015-03-07 03:44:31 +08:00
|
|
|
float h[4];
|
2015-03-02 05:22:09 +08:00
|
|
|
bool use_roi, use_image;
|
2014-02-17 01:54:51 +08:00
|
|
|
|
2014-03-18 20:02:25 +08:00
|
|
|
TEST_DECLARE_INPUT_PARAMETER(src);
|
|
|
|
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
2014-02-17 01:54:51 +08:00
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
cn = GET_PARAM(0);
|
|
|
|
use_roi = GET_PARAM(1);
|
2015-03-02 05:22:09 +08:00
|
|
|
use_image = GET_PARAM(2);
|
2014-02-17 01:54:51 +08:00
|
|
|
|
|
|
|
templateWindowSize = 7;
|
|
|
|
searchWindowSize = 21;
|
2015-03-07 03:44:31 +08:00
|
|
|
|
|
|
|
ASSERT_TRUE(cn > 0 && cn <= 4);
|
|
|
|
for (int i=0; i<cn; i++)
|
|
|
|
h[i] = 3.0f + 0.5f*i;
|
2014-02-17 01:54:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void generateTestData()
|
|
|
|
{
|
2015-03-02 05:22:09 +08:00
|
|
|
const int type = CV_8UC(cn);
|
2014-03-11 19:21:14 +08:00
|
|
|
Mat image;
|
2015-03-02 05:22:09 +08:00
|
|
|
|
|
|
|
if (use_image) {
|
|
|
|
image = readImage("denoising/lena_noised_gaussian_sigma=10.png",
|
|
|
|
cn == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
|
2014-03-11 19:21:14 +08:00
|
|
|
ASSERT_FALSE(image.empty());
|
|
|
|
}
|
|
|
|
|
2015-03-02 05:22:09 +08:00
|
|
|
Size roiSize = use_image ? image.size() : randomSize(1, MAX_VALUE);
|
2014-02-17 01:54:51 +08:00
|
|
|
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255);
|
2015-03-02 05:22:09 +08:00
|
|
|
if (use_image) {
|
|
|
|
if (cn == 2) {
|
|
|
|
int from_to[] = { 0,0, 1,1 };
|
|
|
|
src_roi.create(roiSize, type);
|
|
|
|
mixChannels(&image, 1, &src_roi, 1, from_to, 2);
|
|
|
|
}
|
2015-03-03 08:20:33 +08:00
|
|
|
else if (cn == 4) {
|
|
|
|
int from_to[] = { 0,0, 1,1, 2,2, 1,3};
|
|
|
|
src_roi.create(roiSize, type);
|
|
|
|
mixChannels(&image, 1, &src_roi, 1, from_to, 4);
|
|
|
|
}
|
2015-03-02 05:22:09 +08:00
|
|
|
else image.copyTo(src_roi);
|
|
|
|
}
|
2014-02-17 01:54:51 +08:00
|
|
|
|
|
|
|
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
|
|
|
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255);
|
|
|
|
|
2014-03-18 20:02:25 +08:00
|
|
|
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
|
|
|
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
2014-02-17 01:54:51 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising;
|
|
|
|
|
|
|
|
OCL_TEST_P(FastNlMeansDenoising, Mat)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < test_loop_times; j++)
|
|
|
|
{
|
|
|
|
generateTestData();
|
|
|
|
|
2015-03-07 03:44:31 +08:00
|
|
|
OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h[0], templateWindowSize, searchWindowSize));
|
|
|
|
OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h[0], templateWindowSize, searchWindowSize));
|
|
|
|
|
|
|
|
OCL_EXPECT_MATS_NEAR(dst, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising_hsep;
|
|
|
|
|
|
|
|
OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < test_loop_times; j++)
|
|
|
|
{
|
|
|
|
generateTestData();
|
|
|
|
|
2014-02-17 01:54:51 +08:00
|
|
|
OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize));
|
|
|
|
OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize));
|
|
|
|
|
2014-03-18 20:02:25 +08:00
|
|
|
OCL_EXPECT_MATS_NEAR(dst, 1);
|
2014-02-17 01:54:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 05:22:09 +08:00
|
|
|
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingAbs;
|
|
|
|
|
|
|
|
OCL_TEST_P(FastNlMeansDenoisingAbs, Mat)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < test_loop_times; j++)
|
|
|
|
{
|
|
|
|
generateTestData();
|
|
|
|
|
2015-03-07 03:44:31 +08:00
|
|
|
OCL_OFF(cv::fastNlMeansDenoisingAbs(src_roi, dst_roi, h[0], templateWindowSize, searchWindowSize));
|
|
|
|
OCL_ON(cv::fastNlMeansDenoisingAbs(usrc_roi, udst_roi, h[0], templateWindowSize, searchWindowSize));
|
|
|
|
|
|
|
|
OCL_EXPECT_MATS_NEAR(dst, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingAbs_hsep;
|
|
|
|
|
|
|
|
OCL_TEST_P(FastNlMeansDenoisingAbs_hsep, Mat)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < test_loop_times; j++)
|
|
|
|
{
|
|
|
|
generateTestData();
|
|
|
|
|
2015-03-02 05:22:09 +08:00
|
|
|
OCL_OFF(cv::fastNlMeansDenoisingAbs(src_roi, dst_roi, h, templateWindowSize, searchWindowSize));
|
|
|
|
OCL_ON(cv::fastNlMeansDenoisingAbs(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize));
|
|
|
|
|
|
|
|
OCL_EXPECT_MATS_NEAR(dst, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 18:29:02 +08:00
|
|
|
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored;
|
2014-02-19 22:34:34 +08:00
|
|
|
|
2014-03-18 18:29:02 +08:00
|
|
|
OCL_TEST_P(FastNlMeansDenoisingColored, Mat)
|
2014-02-19 22:34:34 +08:00
|
|
|
{
|
|
|
|
for (int j = 0; j < test_loop_times; j++)
|
|
|
|
{
|
|
|
|
generateTestData();
|
|
|
|
|
2015-03-07 03:44:31 +08:00
|
|
|
OCL_OFF(cv::fastNlMeansDenoisingColored(src_roi, dst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
|
|
|
|
OCL_ON(cv::fastNlMeansDenoisingColored(usrc_roi, udst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
|
2014-02-19 22:34:34 +08:00
|
|
|
|
2014-03-18 20:02:25 +08:00
|
|
|
OCL_EXPECT_MATS_NEAR(dst, 1);
|
2014-02-19 22:34:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 05:22:09 +08:00
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising,
|
2015-03-07 03:44:31 +08:00
|
|
|
Combine(Values(1, 2, 3, 4), Bool(), Values(true)));
|
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising_hsep,
|
|
|
|
Combine(Values(1, 2, 3, 4), Bool(), Values(true)));
|
2015-03-02 05:22:09 +08:00
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingAbs,
|
2015-03-07 03:44:31 +08:00
|
|
|
Combine(Values(1, 2, 3, 4), Bool(), Values(true)));
|
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingAbs_hsep,
|
|
|
|
Combine(Values(1, 2, 3, 4), Bool(), Values(true)));
|
2015-03-02 05:22:09 +08:00
|
|
|
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored,
|
|
|
|
Combine(Values(3, 4), Bool(), Values(false)));
|
2014-02-17 01:54:51 +08:00
|
|
|
|
|
|
|
} } // namespace cvtest::ocl
|
|
|
|
|
|
|
|
#endif // HAVE_OPENCL
|