summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/sift/src/matlab/imsmooth.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/matlab/imsmooth.c')
-rw-r--r--SD-VBS/benchmarks/sift/src/matlab/imsmooth.c115
1 files changed, 0 insertions, 115 deletions
diff --git a/SD-VBS/benchmarks/sift/src/matlab/imsmooth.c b/SD-VBS/benchmarks/sift/src/matlab/imsmooth.c
deleted file mode 100644
index 5d6a660..0000000
--- a/SD-VBS/benchmarks/sift/src/matlab/imsmooth.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/** file: imsmooth.c
2 ** author: Andrea Vedaldi
3 ** description: Smooth an image.
4 **/
5
6#include"mex.h"
7#include<stdlib.h>
8#include<string.h>
9#include<math.h>
10#include<assert.h>
11
12#define greater(a,b) ((a) > (b))
13#define min(a,b) (((a)<(b))?(a):(b))
14#define max(a,b) (((a)>(b))?(a):(b))
15
16const double win_factor = 1.5 ;
17const int nbins = 36 ;
18
19void
20mexFunction(int nout, mxArray *out[],
21 int nin, const mxArray *in[])
22{
23 int M,N ;
24 double* I_pt ;
25 double* J_pt ;
26 double s ;
27 enum {I=0,S} ;
28 enum {J=0} ;
29
30 /* ------------------------------------------------------------------
31 ** Check the arguments
32 ** --------------------------------------------------------------- */
33 if (nin != 2) {
34 mexErrMsgTxt("Exactly two input arguments required.");
35 } else if (nout > 1) {
36 mexErrMsgTxt("Too many output arguments.");
37 }
38
39 if (!mxIsDouble(in[I]) ||
40 !mxIsDouble(in[S]) ) {
41 mexErrMsgTxt("All arguments must be real.") ;
42 }
43
44 if(mxGetNumberOfDimensions(in[I]) > 2||
45 mxGetNumberOfDimensions(in[S]) > 2) {
46 mexErrMsgTxt("I must be a two dimensional array and S a scalar.") ;
47 }
48
49 if(max(mxGetM(in[S]),mxGetN(in[S])) > 1) {
50 mexErrMsgTxt("S must be a scalar.\n") ;
51 }
52
53 M = mxGetM(in[I]) ;
54 N = mxGetN(in[I]) ;
55
56 out[J] = mxCreateDoubleMatrix(M, N, mxREAL) ;
57
58 I_pt = mxGetPr(in[I]) ;
59 J_pt = mxGetPr(out[J]) ;
60 s = *mxGetPr(in[S]) ;
61
62 /* ------------------------------------------------------------------
63 ** Do the job
64 ** --------------------------------------------------------------- */
65 if(s > 0.01) {
66
67 int W = (int) ceil(4*s) ;
68 int i ;
69 int j ;
70 double* g0 = (double*) mxMalloc( (2*W+1)*sizeof(double) ) ;
71 double* buffer = (double*) mxMalloc( M*N*sizeof(double) ) ;
72 double acc=0.0 ;
73
74 for(j = 0 ; j < 2*W+1 ; ++j) {
75 g0[j] = exp(-0.5 * (j - W)*(j - W)/(s*s)) ;
76 acc += g0[j] ;
77 }
78 for(j = 0 ; j < 2*W+1 ; ++j) {
79 g0[j] /= acc ;
80 }
81
82 /*
83 ** Convolve along the columns
84 **/
85 for(j = 0 ; j < N ; ++j) {
86 for(i = 0 ; i < M ; ++i) {
87 double* start = I_pt + max(i-W,0) + j*M ;
88 double* stop = I_pt + min(i+W,M-1) + j*M + 1 ;
89 double* g = g0 + max(0, W-i) ;
90 acc = 0.0 ;
91 while(stop != start) acc += (*g++) * (*start++) ;
92 *buffer++ = acc ;
93 }
94 }
95 buffer -= M*N ;
96
97 /*
98 ** Convolve along the rows
99 **/
100 for(j = 0 ; j < N ; ++j) {
101 for(i = 0 ; i < M ; ++i) {
102 double* start = buffer + i + max(j-W,0)*M ;
103 double* stop = buffer + i + min(j+W,N-1)*M + M ;
104 double* g = g0 + max(0, W-j) ;
105 acc = 0.0 ;
106 while(stop != start) { acc += (*g++) * (*start) ; start+=M ;}
107 *J_pt++ = acc ;
108 }
109 }
110 mxFree(buffer) ;
111 mxFree(g0) ;
112 } else {
113 memcpy(J_pt, I_pt, sizeof(double)*M*N) ;
114 }
115}