From 9b31e6cd4478d245d493bbff2e2ea373fee524f7 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 11 Mar 2014 15:21:14 +0400 Subject: [PATCH] changes according to reviewer's suggestions --- modules/photo/src/fast_nlmeans_denoising_opencl.hpp | 14 +++----------- modules/photo/test/ocl/test_denoising.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp index a121321..ad1d942 100644 --- a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp @@ -22,14 +22,6 @@ enum CTA_SIZE = 256 }; -static inline int getNearestPowerOf2OpenCL(int value) -{ - int p = 0; - while (1 << p < value) - ++p; - return p; -} - static int divUp(int a, int b) { return (a + b - 1) / b; @@ -51,7 +43,7 @@ static bool ocl_calcAlmostDist2Weight(UMat & almostDist2Weight, int searchWindow // additional optimization of precalced weights to replace division(averaging) by binary shift CV_Assert(templateWindowSize <= 46340); // sqrt(INT_MAX) int templateWindowSizeSq = templateWindowSize * templateWindowSize; - almostTemplateWindowSizeSqBinShift = getNearestPowerOf2OpenCL(templateWindowSizeSq); + almostTemplateWindowSizeSqBinShift = getNearestPowerOf2(templateWindowSizeSq); FT almostDist2ActualDistMultiplier = (FT)(1 << almostTemplateWindowSizeSqBinShift) / templateWindowSizeSq; const FT WEIGHT_THRESHOLD = 1e-3f; @@ -77,10 +69,10 @@ static bool ocl_calcAlmostDist2Weight(UMat & almostDist2Weight, int searchWindow static bool ocl_fastNlMeansDenoising(InputArray _src, OutputArray _dst, float h, int templateWindowSize, int searchWindowSize) { - int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); + int type = _src.type(), cn = CV_MAT_CN(type); Size size = _src.size(); - if ( !(depth == CV_8U && cn <= 4 && cn != 3) ) + if ( type != CV_8UC1 || type != CV_8UC2 || type != CV_8UC4 ) return false; int templateWindowHalfWize = templateWindowSize / 2; diff --git a/modules/photo/test/ocl/test_denoising.cpp b/modules/photo/test/ocl/test_denoising.cpp index 819c65d..745a457 100644 --- a/modules/photo/test/ocl/test_denoising.cpp +++ b/modules/photo/test/ocl/test_denoising.cpp @@ -34,11 +34,20 @@ PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, bool) virtual void generateTestData() { + Mat image; + if (cn == 1) + { + image = readImage("denoising/lena_noised_gaussian_sigma=10.png", IMREAD_GRAYSCALE); + ASSERT_FALSE(image.empty()); + } + const int type = CV_8UC(cn); - Size roiSize = randomSize(1, MAX_VALUE); + Size roiSize = cn == 1 ? image.size() : randomSize(1, MAX_VALUE); Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0); randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255); + if (cn == 1) + image.copyTo(src_roi); Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0); randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255); -- 2.7.4