summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c')
-rwxr-xr-xSD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c223
1 files changed, 0 insertions, 223 deletions
diff --git a/SD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c b/SD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c
deleted file mode 100755
index 893d346..0000000
--- a/SD-VBS/benchmarks/mser/src/matlab/old/erfill.mex.c
+++ /dev/null
@@ -1,223 +0,0 @@
1/* file: erfill.mex.c
2** description: Extremal Regions filling
3** author: Andrea Vedaldi
4**/
5
6/* AUTORIGHTS
7Copyright (C) 2006 Regents of the University of California
8All rights reserved
9
10Written by Andrea Vedaldi (UCLA VisionLab).
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met
14
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of the University of California, Berkeley nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
23
24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*/
35
36/** @file
37 ** @brief Maximally Stable Extremal Regions - MEX implementation
38 **/
39
40#include<mexutils.c>
41#include<stdio.h>
42#include<stdlib.h>
43#include<math.h>
44#include<string.h>
45#include<assert.h>
46
47#define MIN(x,y) (((x)<(y))?(x):(y))
48#define MAX(x,y) (((x)>(y))?(x):(y))
49
50typedef char unsigned val_t ;
51typedef int unsigned idx_t ;
52typedef long long int unsigned acc_t ;
53
54/* advance N-dimensional subscript */
55void
56adv(int const* dims, int ndims, int* subs_pt)
57{
58 int d = 0 ;
59 while(d < ndims) {
60 if( ++subs_pt[d] < dims[d] ) return ;
61 subs_pt[d++] = 0 ;
62 }
63}
64
65/* driver */
66void
67mexFunction(int nout, mxArray *out[],
68 int nin, const mxArray *in[])
69{
70
71 enum {IN_I=0, IN_ER} ;
72 enum {OUT_MEMBERS} ;
73
74 idx_t i ;
75 int k, nel, ndims ;
76 int const * dims ;
77 val_t const * I_pt ;
78 int last = 0 ;
79 int last_expanded = 0 ;
80 val_t value = 0 ;
81
82 double const * er_pt ;
83
84 int* subs_pt ; /* N-dimensional subscript */
85 int* nsubs_pt ; /* diff-subscript to point to neigh. */
86 idx_t* strides_pt ; /* strides to move in image array */
87 val_t* visited_pt ; /* flag */
88 idx_t* members_pt ; /* region members */
89
90 /** -----------------------------------------------------------------
91 ** Check the arguments
92 ** -------------------------------------------------------------- */
93 if (nin != 2) {
94 mexErrMsgTxt("Two arguments required.") ;
95 } else if (nout > 4) {
96 mexErrMsgTxt("Too many output arguments.");
97 }
98
99 if(mxGetClassID(in[IN_I]) != mxUINT8_CLASS) {
100 mexErrMsgTxt("I must be of class UINT8.") ;
101 }
102
103 if(!uIsRealScalar(in[IN_ER])) {
104 mexErrMsgTxt("ER must be a DOUBLE scalar.") ;
105 }
106
107 /* get dimensions */
108 nel = mxGetNumberOfElements(in[IN_I]) ;
109 ndims = mxGetNumberOfDimensions(in[IN_I]) ;
110 dims = mxGetDimensions(in[IN_I]) ;
111 I_pt = mxGetData(in[IN_I]) ;
112
113 /* allocate stuff */
114 subs_pt = mxMalloc( sizeof(int) * ndims ) ;
115 nsubs_pt = mxMalloc( sizeof(int) * ndims ) ;
116 strides_pt = mxMalloc( sizeof(idx_t) * ndims ) ;
117 visited_pt = mxMalloc( sizeof(val_t) * nel ) ;
118 members_pt = mxMalloc( sizeof(idx_t) * nel ) ;
119
120 er_pt = mxGetPr(in[IN_ER]) ;
121
122 /* compute strides to move into the N-dimensional image array */
123 strides_pt [0] = 1 ;
124 for(k = 1 ; k < ndims ; ++k) {
125 strides_pt [k] = strides_pt [k-1] * dims [k-1] ;
126 }
127
128 /* load first pixel */
129 memset(visited_pt, 0, sizeof(val_t) * nel) ;
130 {
131 idx_t idx = (idx_t) *er_pt ;
132 if( idx < 1 || idx > nel ) {
133 char buff[80] ;
134 snprintf(buff,80,"ER=%d out of range [1,%d]",idx,nel) ;
135 mexErrMsgTxt(buff) ;
136 }
137 members_pt [last++] = idx - 1 ;
138 }
139 value = I_pt[ members_pt[0] ] ;
140
141 /* -----------------------------------------------------------------
142 * Fill region
143 * -------------------------------------------------------------- */
144 while(last_expanded < last) {
145
146 /* pop next node xi */
147 idx_t index = members_pt[last_expanded++] ;
148
149 /* convert index into a subscript sub; also initialize nsubs
150 to (-1,-1,...,-1) */
151 {
152 idx_t temp = index ;
153 for(k = ndims-1 ; k >=0 ; --k) {
154 nsubs_pt [k] = -1 ;
155 subs_pt [k] = temp / strides_pt [k] ;
156 temp = temp % strides_pt [k] ;
157 }
158 }
159
160 /* process neighbors of xi */
161 while( true ) {
162 int good = true ;
163 idx_t nindex = 0 ;
164
165 /* compute NSUBS+SUB, the correspoinding neighbor index NINDEX
166 and check that the pixel is within image boundaries. */
167 for(k = 0 ; k < ndims && good ; ++k) {
168 int temp = nsubs_pt [k] + subs_pt [k] ;
169 good &= 0 <= temp && temp < dims[k] ;
170 nindex += temp * strides_pt [k] ;
171 }
172
173 /* process neighbor
174 1 - the pixel is within image boundaries;
175 2 - the pixel is indeed different from the current node
176 (this happens when nsub=(0,0,...,0));
177 3 - the pixel has value not greather than val
178 is a pixel older than xi
179 4 - the pixel has not been visited yet
180 */
181 if(good
182 && nindex != index
183 && I_pt [nindex] <= value
184 && ! visited_pt [nindex] ) {
185
186 /* mark as visited */
187 visited_pt [nindex] = 1 ;
188
189 /* add to list */
190 members_pt [last++] = nindex ;
191 }
192
193 /* move to next neighbor */
194 k = 0 ;
195 while(++ nsubs_pt [k] > 1) {
196 nsubs_pt [k++] = -1 ;
197 if(k == ndims) goto done_all_neighbors ;
198 }
199 } /* next neighbor */
200 done_all_neighbors : ;
201 } /* goto pop next member */
202
203 /*
204 * Save results
205 */
206 {
207 int dims[2] ;
208 int unsigned * pt ;
209 dims[0] = last ;
210 out[OUT_MEMBERS] = mxCreateNumericArray(1,dims,mxUINT32_CLASS,mxREAL);
211 pt = mxGetData(out[OUT_MEMBERS]) ;
212 for (i = 0 ; i < last ; ++i) {
213 *pt++ = members_pt[i] + 1 ;
214 }
215 }
216
217 /* free stuff */
218 mxFree( members_pt ) ;
219 mxFree( visited_pt ) ;
220 mxFree( strides_pt ) ;
221 mxFree( nsubs_pt ) ;
222 mxFree( subs_pt ) ;
223}