Path: blob/master/modules/photo/test/test_denoising.cuda.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "test_precomp.hpp"4344#include "opencv2/photo/cuda.hpp"45#include "opencv2/ts/cuda_test.hpp"4647#include "opencv2/opencv_modules.hpp"48#include "cvconfig.h"4950#if defined (HAVE_CUDA) && defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAIMGPROC)5152namespace opencv_test { namespace {5354////////////////////////////////////////////////////////55// Brute Force Non local means5657TEST(CUDA_BruteForceNonLocalMeans, Regression)58{59using cv::cuda::GpuMat;6061cv::Mat bgr = readImage("../gpu/denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);62ASSERT_FALSE(bgr.empty());63cv::resize(bgr, bgr, cv::Size(256, 256));6465cv::Mat gray;66cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);6768GpuMat dbgr, dgray;69cv::cuda::nonLocalMeans(GpuMat(bgr), dbgr, 20);70cv::cuda::nonLocalMeans(GpuMat(gray), dgray, 20);7172#if 073dumpImage("../gpu/denoising/nlm_denoised_lena_bgr.png", cv::Mat(dbgr));74dumpImage("../gpu/denoising/nlm_denoised_lena_gray.png", cv::Mat(dgray));75#endif7677cv::Mat bgr_gold = readImage("../gpu/denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);78cv::Mat gray_gold = readImage("../gpu/denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);79ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());80cv::resize(bgr_gold, bgr_gold, cv::Size(256, 256));81cv::resize(gray_gold, gray_gold, cv::Size(256, 256));8283EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);84EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4);85}8687////////////////////////////////////////////////////////88// Fast Force Non local means8990TEST(CUDA_FastNonLocalMeans, Regression)91{92using cv::cuda::GpuMat;9394cv::Mat bgr = readImage("../gpu/denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);95ASSERT_FALSE(bgr.empty());9697cv::Mat gray;98cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);99100GpuMat dbgr, dgray;101102cv::cuda::fastNlMeansDenoising(GpuMat(gray), dgray, 20);103cv::cuda::fastNlMeansDenoisingColored(GpuMat(bgr), dbgr, 20, 10);104105#if 0106dumpImage("../gpu/denoising/fnlm_denoised_lena_bgr.png", cv::Mat(dbgr));107dumpImage("../gpu/denoising/fnlm_denoised_lena_gray.png", cv::Mat(dgray));108#endif109110cv::Mat bgr_gold = readImage("../gpu/denoising/fnlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);111cv::Mat gray_gold = readImage("../gpu/denoising/fnlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);112ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());113114EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);115EXPECT_MAT_NEAR(gray_gold, dgray, 1);116}117118}} // namespace119#endif // HAVE_CUDA120121122