[arrayfire] 07/29: Improved SIFT descriptor scaling

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Oct 19 17:48:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository arrayfire.

commit 6b6ce7287085675cfeb6475bb02c0d64789bcca8
Author: Peter Andreas Entschev <peter at arrayfire.com>
Date:   Mon Oct 5 14:01:00 2015 -0400

    Improved SIFT descriptor scaling
---
 src/backend/cpu/sift_nonfree.hpp           |  9 ++++-----
 src/backend/cuda/kernel/sift_nonfree.hpp   | 11 ++++++-----
 src/backend/opencl/kernel/sift_nonfree.cl  |  5 ++---
 src/backend/opencl/kernel/sift_nonfree.hpp |  4 ++--
 test/sift_nonfree.cpp                      |  6 +++++-
 5 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/backend/cpu/sift_nonfree.hpp b/src/backend/cpu/sift_nonfree.hpp
index b331e4c..6b4ef71 100644
--- a/src/backend/cpu/sift_nonfree.hpp
+++ b/src/backend/cpu/sift_nonfree.hpp
@@ -402,7 +402,7 @@ namespace cpu
                 y_out[*counter] = (y + xy) * (1 << octave);
                 layer_out[*counter] = layer;
                 response_out[*counter] = abs(contr);
-                size_out[*counter] = sigma*pow(2.f, octave + (layer + xl) / n_layers);
+                size_out[*counter] = sigma*pow(2.f, octave + (layer + xl) / n_layers) * 2.f;
                 (*counter)++;
             }
         }
@@ -613,7 +613,6 @@ namespace cpu
         const int d,
         const int n,
         const float scale,
-        const float sigma,
         const unsigned octave,
         const unsigned n_layers)
     {
@@ -623,7 +622,7 @@ namespace cpu
             const unsigned layer = layer_in[f];
             float ori = (360.f - ori_in[f]) * PI_VAL / 180.f;
             ori = (ori > PI_VAL) ? ori - PI_VAL*2 : ori;
-            //const float size = size_in[f];
+            const float size = size_in[f];
             const int fx = round(x_in[f] * scale);
             const int fy = round(y_in[f] * scale);
 
@@ -636,7 +635,7 @@ namespace cpu
             float sin_t = sin(ori);
             float bins_per_rad = n / (PI_VAL * 2.f);
             float exp_denom = d * d * 0.5f;
-            float hist_width = DescrSclFctr * sigma * powf(2.f, layer/n_layers);
+            float hist_width = DescrSclFctr * size * scale * 0.5f;
             int radius = hist_width * sqrt(2.f) * (d + 1.f) * 0.5f + 0.5f;
 
             int len = radius*2+1;
@@ -970,7 +969,7 @@ namespace cpu
             computeDescriptor<T>(desc, desc_len,
                                  oriented_x, oriented_y, oriented_layer,
                                  oriented_response, oriented_size, oriented_ori,
-                                 oriented_feat, gauss_pyr, d, n, scale, init_sigma, i, n_layers);
+                                 oriented_feat, gauss_pyr, d, n, scale, i, n_layers);
 
             total_feat += oriented_feat;
             feat_pyr[i] = oriented_feat;
diff --git a/src/backend/cuda/kernel/sift_nonfree.hpp b/src/backend/cuda/kernel/sift_nonfree.hpp
index c8de759..1a1c35f 100644
--- a/src/backend/cuda/kernel/sift_nonfree.hpp
+++ b/src/backend/cuda/kernel/sift_nonfree.hpp
@@ -504,7 +504,7 @@ __global__ void interpolateExtrema(
             y_out[ridx] = (y + xy) * (1 << octave);
             layer_out[ridx] = layer;
             response_out[ridx] = abs(contr);
-            size_out[ridx] = sigma*pow(2.f, octave + (layer + xl) / n_layers);
+            size_out[ridx] = sigma*pow(2.f, octave + (layer + xl) / n_layers) * 2.f;
         }
     }
 }
@@ -745,7 +745,6 @@ __global__ void computeDescriptor(
     const int d,
     const int n,
     const float scale,
-    const float sigma,
     const int n_layers)
 {
     const int tid_x = threadIdx.x;
@@ -770,7 +769,7 @@ __global__ void computeDescriptor(
         const unsigned layer = layer_in[f];
         float ori = (360.f - ori_in[f]) * PI_VAL / 180.f;
         ori = (ori > PI_VAL) ? ori - PI_VAL*2 : ori;
-        //const float size = size_in[f];
+        const float size = size_in[f];
         const int fx = round(x_in[f] * scale);
         const int fy = round(y_in[f] * scale);
 
@@ -785,7 +784,7 @@ __global__ void computeDescriptor(
         float sin_t = sinf(ori);
         float bins_per_rad = n / (PI_VAL * 2.f);
         float exp_denom = d * d * 0.5f;
-        float hist_width = DESCR_SCL_FCTR * sigma * powf(2.f, layer/n_layers);
+        float hist_width = DESCR_SCL_FCTR * size * scale * 0.5f;
         int radius = hist_width * sqrtf(2.f) * (d + 1.f) * 0.5f + 0.5f;
 
         int len = radius*2+1;
@@ -999,6 +998,8 @@ std::vector< Param<T> > buildGaussPyr(
 
                 Param<convAccT> filter = gauss_filter<convAccT>(sig_layers[l]);
 
+
+
                 convolve2<T, convAccT, 0, false>(tmp, tmp_pyr[src_idx], filter);
                 convolve2<T, convAccT, 1, false>(tmp_pyr[idx], CParam<T>(tmp), filter);
 
@@ -1305,7 +1306,7 @@ void sift(unsigned* out_feat,
                          d_desc, desc_len, histsz,
                          d_oriented_x, d_oriented_y, d_oriented_layer,
                          d_oriented_response, d_oriented_size, d_oriented_ori,
-                         oriented_feat, gauss_pyr[i], d, n, scale, init_sigma, n_layers);
+                         oriented_feat, gauss_pyr[i], d, n, scale, n_layers);
         POST_LAUNCH_CHECK();
 
         total_feat += oriented_feat;
diff --git a/src/backend/opencl/kernel/sift_nonfree.cl b/src/backend/opencl/kernel/sift_nonfree.cl
index ef63cab..7a65ffa 100644
--- a/src/backend/opencl/kernel/sift_nonfree.cl
+++ b/src/backend/opencl/kernel/sift_nonfree.cl
@@ -434,7 +434,7 @@ __kernel void interpolateExtrema(
             y_out[ridx] = (y + xy) * (1 << octave);
             layer_out[ridx] = layer;
             response_out[ridx] = fabs(contr);
-            size_out[ridx] = sigma*pow(2.f, octave + (layer + xl) / n_layers);
+            size_out[ridx] = sigma*pow(2.f, octave + (layer + xl) / n_layers) * 2.f;
         }
     }
 }
@@ -677,7 +677,6 @@ __kernel void computeDescriptor(
     const int d,
     const int n,
     const float scale,
-    const float sigma,
     const int n_layers,
     __local float* l_mem)
 {
@@ -713,7 +712,7 @@ __kernel void computeDescriptor(
         float sin_t = sin(ori);
         float bins_per_rad = n / (PI_VAL * 2.f);
         float exp_denom = d * d * 0.5f;
-        float hist_width = DESCR_SCL_FCTR * sigma * pow(2.f, layer/n_layers);
+        float hist_width = DESCR_SCL_FCTR * size * scale * 0.5f;
         int radius = hist_width * sqrt(2.f) * (d + 1.f) * 0.5f + 0.5f;
 
         int len = radius*2+1;
diff --git a/src/backend/opencl/kernel/sift_nonfree.hpp b/src/backend/opencl/kernel/sift_nonfree.hpp
index 9c36a3f..bc65516 100644
--- a/src/backend/opencl/kernel/sift_nonfree.hpp
+++ b/src/backend/opencl/kernel/sift_nonfree.hpp
@@ -669,14 +669,14 @@ void sift(unsigned* out_feat,
 
             auto cdOp = make_kernel<Buffer, unsigned, unsigned,
                                     Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, unsigned,
-                                    Buffer, KParam, int, int, float, float, int,
+                                    Buffer, KParam, int, int, float, int,
                                     LocalSpaceArg> (*cdKernel[device]);
 
             cdOp(EnqueueArgs(getQueue(), global_desc, local_desc),
                  *d_desc, desc_len, histsz,
                  *d_oriented_x, *d_oriented_y, *d_oriented_layer,
                  *d_oriented_response, *d_oriented_size, *d_oriented_ori, oriented_feat,
-                 *gauss_pyr[o].data, gauss_pyr[o].info, d, n, scale, init_sigma, n_layers,
+                 *gauss_pyr[o].data, gauss_pyr[o].info, d, n, scale, n_layers,
                  cl::Local(desc_len * (histsz+1) * sizeof(float)));
             CL_DEBUG_FINISH(getQueue());
 
diff --git a/test/sift_nonfree.cpp b/test/sift_nonfree.cpp
index f5bd8a4..7e7f6c4 100644
--- a/test/sift_nonfree.cpp
+++ b/test/sift_nonfree.cpp
@@ -234,7 +234,11 @@ void siftTest(string pTestFile)
             ASSERT_LE(fabs(out_feat[elIter].f[4] - gold_feat[elIter].f[4]), 1e-3) << "at: " << elIter << std::endl;
         }
 
-        EXPECT_TRUE(compareEuclidean(descDims[0], descDims[1], (float*)&v_out_desc[0], (float*)&v_gold_desc[0], 1.f, 2.f));
+        bool isTypeDouble = is_same_type<T, double>::value || is_same_type<T, af::cdouble>::value;
+        if (isTypeDouble)
+            EXPECT_TRUE(compareEuclidean(descDims[0], descDims[1], (float*)&v_out_desc[0], (float*)&v_gold_desc[0], 2.f, 4.5f));
+        else
+            EXPECT_TRUE(compareEuclidean(descDims[0], descDims[1], (float*)&v_out_desc[0], (float*)&v_gold_desc[0], 1.f, 2.f));
 
         ASSERT_EQ(AF_SUCCESS, af_release_array(inArray));
         ASSERT_EQ(AF_SUCCESS, af_release_array(inArray_f32));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list