changes according to reviewer's suggestions
authorIlya Lavrenov <ilya.lavrenov@itseez.com>
Tue, 11 Mar 2014 11:21:14 +0000 (15:21 +0400)
committerIlya Lavrenov <ilya.lavrenov@itseez.com>
Tue, 11 Mar 2014 11:40:31 +0000 (15:40 +0400)
modules/photo/src/fast_nlmeans_denoising_opencl.hpp
modules/photo/test/ocl/test_denoising.cpp

index a121321..ad1d942 100644 (file)
@@ -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;
index 819c65d..745a457 100644 (file)
@@ -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);