Path: blob/master/modules/photo/test/ocl/test_denoising.cpp
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.34// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.5// Third party copyrights are property of their respective owners.67#include "../test_precomp.hpp"8#include "opencv2/ts/ocl_test.hpp"910#ifdef HAVE_OPENCL1112namespace opencv_test {13namespace ocl {1415PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, int, bool, bool)16{17int cn, normType, templateWindowSize, searchWindowSize;18std::vector<float> h;19bool use_roi, use_image;2021TEST_DECLARE_INPUT_PARAMETER(src);22TEST_DECLARE_OUTPUT_PARAMETER(dst);2324virtual void SetUp()25{26cn = GET_PARAM(0);27normType = GET_PARAM(1);28use_roi = GET_PARAM(2);29use_image = GET_PARAM(3);3031templateWindowSize = 7;32searchWindowSize = 21;3334h.resize(cn);35for (int i=0; i<cn; i++)36h[i] = 3.0f + 0.5f*i;37}3839void generateTestData()40{41const int type = CV_8UC(cn);42Mat image;4344if (use_image) {45image = readImage("denoising/lena_noised_gaussian_sigma=10.png",46cn == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);47ASSERT_FALSE(image.empty());48}4950Size roiSize = use_image ? image.size() : randomSize(1, MAX_VALUE);51Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);52randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255);53if (use_image) {54ASSERT_TRUE(cn > 0 && cn <= 4);55if (cn == 2) {56int from_to[] = { 0,0, 1,1 };57src_roi.create(roiSize, type);58mixChannels(&image, 1, &src_roi, 1, from_to, 2);59}60else if (cn == 4) {61int from_to[] = { 0,0, 1,1, 2,2, 1,3};62src_roi.create(roiSize, type);63mixChannels(&image, 1, &src_roi, 1, from_to, 4);64}65else image.copyTo(src_roi);66}6768Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);69randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255);7071UMAT_UPLOAD_INPUT_PARAMETER(src);72UMAT_UPLOAD_OUTPUT_PARAMETER(dst);73}74};7576typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising;7778OCL_TEST_P(FastNlMeansDenoising, Mat)79{80for (int j = 0; j < test_loop_times; j++)81{82generateTestData();8384OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));85OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));8687OCL_EXPECT_MATS_NEAR(dst, 1);88}89}9091typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising_hsep;9293OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)94{95for (int j = 0; j < test_loop_times; j++)96{97generateTestData();9899OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize, normType));100OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize, normType));101102OCL_EXPECT_MATS_NEAR(dst, 1);103}104}105106typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored;107108OCL_TEST_P(FastNlMeansDenoisingColored, Mat)109{110for (int j = 0; j < test_loop_times; j++)111{112generateTestData();113114OCL_OFF(cv::fastNlMeansDenoisingColored(src_roi, dst_roi, h[0], h[0], templateWindowSize, searchWindowSize));115OCL_ON(cv::fastNlMeansDenoisingColored(usrc_roi, udst_roi, h[0], h[0], templateWindowSize, searchWindowSize));116117OCL_EXPECT_MATS_NEAR(dst, 1);118}119}120121OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising,122Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),123Bool(), Values(true)));124OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising_hsep,125Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),126Bool(), Values(true)));127OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored,128Combine(Values(3, 4), Values((int)NORM_L2), Bool(), Values(false)));129130} } // namespace opencv_test::ocl131132#endif // HAVE_OPENCL133134135