summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/sift/src/matlab/siftmatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/matlab/siftmatch.c')
-rw-r--r--SD-VBS/benchmarks/sift/src/matlab/siftmatch.c250
1 files changed, 0 insertions, 250 deletions
diff --git a/SD-VBS/benchmarks/sift/src/matlab/siftmatch.c b/SD-VBS/benchmarks/sift/src/matlab/siftmatch.c
deleted file mode 100644
index 1150176..0000000
--- a/SD-VBS/benchmarks/sift/src/matlab/siftmatch.c
+++ /dev/null
@@ -1,250 +0,0 @@
1/* file: siftmatch.c
2** author: Andrea Vedaldi
3** description: SIFT descriptor matching.
4**/
5
6/* AUTORIGHTS
7Copyright (c) 2006 The Regents of the University of California.
8All Rights Reserved.
9
10Created by Andrea Vedaldi
11UCLA Vision Lab - Department of Computer Science
12
13Permission to use, copy, modify, and distribute this software and its
14documentation for educational, research and non-profit purposes,
15without fee, and without a written agreement is hereby granted,
16provided that the above copyright notice, this paragraph and the
17following three paragraphs appear in all copies.
18
19This software program and documentation are copyrighted by The Regents
20of the University of California. The software program and
21documentation are supplied "as is", without any accompanying services
22from The Regents. The Regents does not warrant that the operation of
23the program will be uninterrupted or error-free. The end-user
24understands that the program was developed for research purposes and
25is advised not to rely exclusively on the program for any reason.
26
27This software embodies a method for which the following patent has
28been issued: "Method and apparatus for identifying scale invariant
29features in an image and use of same for locating an object in an
30image," David G. Lowe, US Patent 6,711,293 (March 23,
312004). Provisional application filed March 8, 1999. Asignee: The
32University of British Columbia.
33
34IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
35FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
36INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND
37ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
38ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF
39CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
40LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
42BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
43MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44*/
45
46#include"mexutils.c"
47
48#include<stdlib.h>
49#include<string.h>
50#include<math.h>
51
52#define greater(a,b) ((a) > (b))
53#define min(a,b) (((a)<(b))?(a):(b))
54#define max(a,b) (((a)>(b))?(a):(b))
55
56#define TYPEOF_mxDOUBLE_CLASS double
57#define TYPEOF_mxSINGLE_CLASS float
58#define TYPEOF_mxINT8_CLASS char
59#define TYPEOF_mxUINT8_CLASS unsigned char
60
61#define PROMOTE_mxDOUBLE_CLASS double
62#define PROMOTE_mxSINGLE_CLASS float
63#define PROMOTE_mxINT8_CLASS int
64#define PROMOTE_mxUINT8_CLASS int
65
66#define MAXVAL_mxDOUBLE_CLASS mxGetInf()
67#define MAXVAL_mxSINGLE_CLASS ((float)mxGetInf())
68#define MAXVAL_mxINT8_CLASS 0x7fffffff
69#define MAXVAL_mxUINT8_CLASS 0x7fffffff
70
71typedef struct
72{
73 int k1 ;
74 int k2 ;
75 double score ;
76} Pair ;
77
78/*
79 * This macro defines the matching function for abstract type; that
80 * is, it is a sort of C++ template. This is also a good illustration
81 * of why C++ is preferable for templates :-)
82 */
83#define _COMPARE_TEMPLATE(MXC) \
84 Pair* compare_##MXC (Pair* pairs_iterator, \
85 const TYPEOF_##MXC * L1_pt, \
86 const TYPEOF_##MXC * L2_pt, \
87 int K1, int K2, int ND, float thresh) \
88 { \
89 int k1, k2 ; \
90 const PROMOTE_##MXC maxval = MAXVAL_##MXC ; \
91 for(k1 = 0 ; k1 < K1 ; ++k1, L1_pt += ND ) { \
92 \
93 PROMOTE_##MXC best = maxval ; \
94 PROMOTE_##MXC second_best = maxval ; \
95 int bestk = -1 ; \
96 \
97 /* For each point P2[k2] in the second image... */ \
98 for(k2 = 0 ; k2 < K2 ; ++k2, L2_pt += ND) { \
99 \
100 int bin ; \
101 PROMOTE_##MXC acc = 0 ; \
102 for(bin = 0 ; bin < ND ; ++bin) { \
103 PROMOTE_##MXC delta = \
104 ((PROMOTE_##MXC) L1_pt[bin]) - \
105 ((PROMOTE_##MXC) L2_pt[bin]) ; \
106 acc += delta*delta ; \
107 } \
108 \
109 /* Filter the best and second best matching point. */ \
110 if(acc < best) { \
111 second_best = best ; \
112 best = acc ; \
113 bestk = k2 ; \
114 } else if(acc < second_best) { \
115 second_best = acc ; \
116 } \
117 } \
118 \
119 L2_pt -= ND*K2 ; \
120 \
121 /* Lowe's method: accept the match only if unique. */ \
122 if(thresh * (float) best <= (float) second_best && \
123 bestk != -1) { \
124 pairs_iterator->k1 = k1 ; \
125 pairs_iterator->k2 = bestk ; \
126 pairs_iterator->score = best ; \
127 pairs_iterator++ ; \
128 } \
129 } \
130 \
131 return pairs_iterator ; \
132 } \
133
134_COMPARE_TEMPLATE( mxDOUBLE_CLASS )
135_COMPARE_TEMPLATE( mxSINGLE_CLASS )
136_COMPARE_TEMPLATE( mxINT8_CLASS )
137_COMPARE_TEMPLATE( mxUINT8_CLASS )
138
139void
140mexFunction(int nout, mxArray *out[],
141 int nin, const mxArray *in[])
142{
143 int K1, K2, ND ;
144 void* L1_pt ;
145 void* L2_pt ;
146 double thresh = 1.5 ;
147 mxClassID data_class ;
148 enum {L1=0,L2,THRESH} ;
149 enum {MATCHES=0,D} ;
150
151 /* ------------------------------------------------------------------
152 ** Check the arguments
153 ** --------------------------------------------------------------- */
154 if (nin < 2) {
155 mexErrMsgTxt("At least two input arguments required");
156 } else if (nout > 2) {
157 mexErrMsgTxt("Too many output arguments");
158 }
159
160 if(!mxIsNumeric(in[L1]) ||
161 !mxIsNumeric(in[L2]) ||
162 mxGetNumberOfDimensions(in[L1]) > 2 ||
163 mxGetNumberOfDimensions(in[L2]) > 2) {
164 mexErrMsgTxt("L1 and L2 must be two dimensional numeric arrays") ;
165 }
166
167 K1 = mxGetN(in[L1]) ;
168 K2 = mxGetN(in[L2]) ;
169 ND = mxGetM(in[L1]) ;
170
171 if(mxGetM(in[L2]) != ND) {
172 mexErrMsgTxt("L1 and L2 must have the same number of rows") ;
173 }
174
175 data_class = mxGetClassID(in[L1]) ;
176 if(mxGetClassID(in[L2]) != data_class) {
177 mexErrMsgTxt("L1 and L2 must be of the same class") ;
178 }
179
180 L1_pt = mxGetData(in[L1]) ;
181 L2_pt = mxGetData(in[L2]) ;
182
183 if(nin == 3) {
184 if(!uIsRealScalar(in[THRESH])) {
185 mexErrMsgTxt("THRESH should be a real scalar") ;
186 }
187 thresh = *mxGetPr(in[THRESH]) ;
188 } else if(nin > 3) {
189 mexErrMsgTxt("At most three arguments are allowed") ;
190 }
191
192 /* ------------------------------------------------------------------
193 ** Do the job
194 ** --------------------------------------------------------------- */
195 {
196 Pair* pairs_begin = (Pair*) mxMalloc(sizeof(Pair) * (K1+K2)) ;
197 Pair* pairs_iterator = pairs_begin ;
198
199
200#define _DISPATCH_COMPARE( MXC ) \
201 case MXC : \
202 pairs_iterator = compare_##MXC(pairs_iterator, \
203 (const TYPEOF_##MXC*) L1_pt, \
204 (const TYPEOF_##MXC*) L2_pt, \
205 K1,K2,ND,thresh) ; \
206 break ; \
207
208 switch (data_class) {
209 _DISPATCH_COMPARE( mxDOUBLE_CLASS ) ;
210 _DISPATCH_COMPARE( mxSINGLE_CLASS ) ;
211 _DISPATCH_COMPARE( mxINT8_CLASS ) ;
212 _DISPATCH_COMPARE( mxUINT8_CLASS ) ;
213 default :
214 mexErrMsgTxt("Unsupported numeric class") ;
215 break ;
216 }
217
218 /* ---------------------------------------------------------------
219 * Finalize
220 * ------------------------------------------------------------ */
221 {
222 Pair* pairs_end = pairs_iterator ;
223 double* M_pt ;
224 double* D_pt = NULL ;
225
226 out[MATCHES] = mxCreateDoubleMatrix
227 (2, pairs_end-pairs_begin, mxREAL) ;
228
229 M_pt = mxGetPr(out[MATCHES]) ;
230
231 if(nout > 1) {
232 out[D] = mxCreateDoubleMatrix(1,
233 pairs_end-pairs_begin,
234 mxREAL) ;
235 D_pt = mxGetPr(out[D]) ;
236 }
237
238 for(pairs_iterator = pairs_begin ;
239 pairs_iterator < pairs_end ;
240 ++pairs_iterator) {
241 *M_pt++ = pairs_iterator->k1 + 1 ;
242 *M_pt++ = pairs_iterator->k2 + 1 ;
243 if(nout > 1) {
244 *D_pt++ = pairs_iterator->score ;
245 }
246 }
247 }
248 mxFree(pairs_begin) ;
249 }
250}