summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/sift/src/c/imsmooth.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/c/imsmooth.c')
-rw-r--r--SD-VBS/benchmarks/sift/src/c/imsmooth.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/sift/src/c/imsmooth.c b/SD-VBS/benchmarks/sift/src/c/imsmooth.c
new file mode 100644
index 0000000..d901418
--- /dev/null
+++ b/SD-VBS/benchmarks/sift/src/c/imsmooth.c
@@ -0,0 +1,104 @@
1/********************************
2Author: Sravanthi Kota Venkata
3********************************/
4
5#include "sift.h"
6#include <math.h>
7#include <assert.h>
8const double win_factor = 1.5 ;
9const int nbins = 36 ;
10const float threshold = 0.01;
11
12/**
13 This function is similar to imageBlur in common/c folder.
14 Here, we can specify the sigma value for the gaussian filter
15 function.
16**/
17
18void imsmooth(F2D* array, float dsigma, F2D* out)
19{
20 int M,N ;
21 int i,j,k;
22 float s ;
23
24 /* ------------------------------------------------------------------
25 ** Check the arguments
26 ** --------------------------------------------------------------- */
27
28 M = array->height;
29 N = array->width;
30 s = dsigma;
31
32 /* ------------------------------------------------------------------
33 ** Do the job
34 ** --------------------------------------------------------------- */
35 if(s > threshold)
36 {
37 int W = (int) ceil(4*s) ;
38 float temp[2*W+1];
39 F2D* buffer;
40 float acc = 0.0;
41
42 buffer = fSetArray(M,N,0);
43
44 for(j = 0 ; j < (2*W+1) ; ++j)
45 {
46 temp[j] = (float)(expf(-0.5 * (j - W)*(j - W)/(s*s))) ;
47 acc += temp[j];
48 }
49
50 for(j = 0 ; j < (2*W+1) ; ++j)
51 {
52 temp[j] /= acc ;
53 }
54
55 /*
56 ** Convolve along the columns
57 **/
58
59 for(j = 0 ; j < M ; ++j)
60 {
61 for(i = 0 ; i < N ; ++i)
62 {
63 int startCol = MAX(i-W,0);
64 int endCol = MIN(i+W, N-1);
65 int filterStart = MAX(0, W-i);
66
67 assert(j < array->height);
68 assert(j < buffer->height);
69 assert(i < buffer->width);
70 for(k=startCol; k<=endCol; k++) {
71 assert(k < array->width);
72 assert(filterStart < 2*W+1);
73 subsref(buffer,j,i) += subsref(array, j, k) * temp[filterStart++];
74 }
75 }
76 }
77
78 /*
79 ** Convolve along the rows
80 **/
81 for(j = 0 ; j < M ; ++j)
82 {
83 for(i = 0 ; i < N ; ++i)
84 {
85 int startRow = MAX(j-W,0);
86 int endRow = MIN(j+W, M-1);
87 int filterStart = MAX(0, W-j);
88 for(k=startRow; k<=endRow; k++)
89 subsref(out,j,i) += subsref(buffer,k,i) * temp[filterStart++];
90 }
91 }
92
93 fFreeHandle(buffer);
94
95 }
96 else
97 {
98 for(i=0;i<M*N;i++)
99 asubsref(out, i) = asubsref(array, i);
100 }
101
102
103 return;
104}