diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/convolve.c')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/convolve.c | 325 |
1 files changed, 0 insertions, 325 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/convolve.c b/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/convolve.c deleted file mode 100755 index 60a11a4..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/convolve.c +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | /* | ||
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
3 | ;;; File: convolve.c | ||
4 | ;;; Author: Eero Simoncelli | ||
5 | ;;; Description: General convolution code for 2D images | ||
6 | ;;; Creation Date: Spring, 1987. | ||
7 | ;;; MODIFICATIONS: | ||
8 | ;;; 10/89: approximately optimized the choice of register vars on SPARCS. | ||
9 | ;;; 6/96: Switched array types to double float. | ||
10 | ;;; 2/97: made more robust and readable. Added STOP arguments. | ||
11 | ;;; 8/97: Bug: when calling internal_reduce with edges in {reflect1,repeat, | ||
12 | ;;; extend} and an even filter dimension. Solution: embed the filter | ||
13 | ;;; in the upper-left corner of a filter with odd Y and X dimensions. | ||
14 | ;;; ---------------------------------------------------------------- | ||
15 | ;;; Object-Based Vision and Image Understanding System (OBVIUS), | ||
16 | ;;; Copyright 1988, Vision Science Group, Media Laboratory, | ||
17 | ;;; Massachusetts Institute of Technology. | ||
18 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
19 | */ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <math.h> | ||
23 | #include "convolve.h" | ||
24 | |||
25 | /* | ||
26 | -------------------------------------------------------------------- | ||
27 | Correlate FILT with IMAGE, subsampling according to START, STEP, and | ||
28 | STOP parameters, with values placed into RESULT array. RESULT | ||
29 | dimensions should be ceil((stop-start)/step). TEMP should be a | ||
30 | pointer to a temporary double array the size of the filter. | ||
31 | EDGES is a string specifying how to handle boundaries -- see edges.c. | ||
32 | The convolution is done in 9 sections, where the border sections use | ||
33 | specially computed edge-handling filters (see edges.c). The origin | ||
34 | of the filter is assumed to be (floor(x_fdim/2), floor(y_fdim/2)). | ||
35 | ------------------------------------------------------------------------ */ | ||
36 | |||
37 | /* abstract out the inner product computation */ | ||
38 | #define INPROD(XCNR,YCNR) \ | ||
39 | { \ | ||
40 | sum=0.0; \ | ||
41 | for (im_pos=YCNR*x_dim+XCNR, filt_pos=0, x_filt_stop=x_fdim; \ | ||
42 | x_filt_stop<=filt_size; \ | ||
43 | im_pos+=(x_dim-x_fdim), x_filt_stop+=x_fdim) \ | ||
44 | for (; \ | ||
45 | filt_pos<x_filt_stop; \ | ||
46 | filt_pos++, im_pos++) \ | ||
47 | sum+= image[im_pos]*temp[filt_pos]; \ | ||
48 | result[res_pos] = sum; \ | ||
49 | } | ||
50 | |||
51 | int internal_reduce(image, x_dim, y_dim, filt, temp, x_fdim, y_fdim, | ||
52 | x_start, x_step, x_stop, y_start, y_step, y_stop, | ||
53 | result, edges) | ||
54 | register image_type *image, *temp; | ||
55 | register int x_fdim, x_dim; | ||
56 | register image_type *result; | ||
57 | register int x_step, y_step; | ||
58 | int x_start, y_start; | ||
59 | int x_stop, y_stop; | ||
60 | image_type *filt; | ||
61 | int y_dim, y_fdim; | ||
62 | char *edges; | ||
63 | { | ||
64 | register double sum; | ||
65 | register int filt_pos, im_pos, x_filt_stop; | ||
66 | register int x_pos, filt_size = x_fdim*y_fdim; | ||
67 | register int y_pos, res_pos; | ||
68 | register int y_ctr_stop = y_dim - ((y_fdim==1)?0:y_fdim); | ||
69 | register int x_ctr_stop = x_dim - ((x_fdim==1)?0:x_fdim); | ||
70 | register int x_res_dim = (x_stop-x_start+x_step-1)/x_step; | ||
71 | int x_ctr_start = ((x_fdim==1)?0:1); | ||
72 | int y_ctr_start = ((y_fdim==1)?0:1); | ||
73 | int x_fmid = x_fdim/2; | ||
74 | int y_fmid = y_fdim/2; | ||
75 | int base_res_pos; | ||
76 | fptr reflect = edge_function(edges); /* look up edge-handling function */ | ||
77 | |||
78 | if (!reflect) return(-1); | ||
79 | |||
80 | /* shift start/stop coords to filter upper left hand corner */ | ||
81 | x_start -= x_fmid; y_start -= y_fmid; | ||
82 | x_stop -= x_fmid; y_stop -= y_fmid; | ||
83 | |||
84 | if (x_stop < x_ctr_stop) x_ctr_stop = x_stop; | ||
85 | if (y_stop < y_ctr_stop) y_ctr_stop = y_stop; | ||
86 | |||
87 | for (res_pos=0, y_pos=y_start; /* TOP ROWS */ | ||
88 | y_pos<y_ctr_start; | ||
89 | y_pos+=y_step) | ||
90 | { | ||
91 | for (x_pos=x_start; /* TOP-LEFT CORNER */ | ||
92 | x_pos<x_ctr_start; | ||
93 | x_pos+=x_step, res_pos++) | ||
94 | { | ||
95 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-1,temp,REDUCE); | ||
96 | INPROD(0,0) | ||
97 | } | ||
98 | |||
99 | (*reflect)(filt,x_fdim,y_fdim,0,y_pos-1,temp,REDUCE); | ||
100 | for (; /* TOP EDGE */ | ||
101 | x_pos<x_ctr_stop; | ||
102 | x_pos+=x_step, res_pos++) | ||
103 | INPROD(x_pos,0) | ||
104 | |||
105 | for (; /* TOP-RIGHT CORNER */ | ||
106 | x_pos<x_stop; | ||
107 | x_pos+=x_step, res_pos++) | ||
108 | { | ||
109 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-1,temp,REDUCE); | ||
110 | INPROD(x_ctr_stop,0) | ||
111 | } | ||
112 | } /* end TOP ROWS */ | ||
113 | |||
114 | y_ctr_start = y_pos; /* hold location of top */ | ||
115 | for (base_res_pos=res_pos, x_pos=x_start; /* LEFT EDGE */ | ||
116 | x_pos<x_ctr_start; | ||
117 | x_pos+=x_step, base_res_pos++) | ||
118 | { | ||
119 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,0,temp,REDUCE); | ||
120 | for (y_pos=y_ctr_start, res_pos=base_res_pos; | ||
121 | y_pos<y_ctr_stop; | ||
122 | y_pos+=y_step, res_pos+=x_res_dim) | ||
123 | INPROD(0,y_pos) | ||
124 | } | ||
125 | |||
126 | (*reflect)(filt,x_fdim,y_fdim,0,0,temp,REDUCE); | ||
127 | for (; /* CENTER */ | ||
128 | x_pos<x_ctr_stop; | ||
129 | x_pos+=x_step, base_res_pos++) | ||
130 | for (y_pos=y_ctr_start, res_pos=base_res_pos; | ||
131 | y_pos<y_ctr_stop; | ||
132 | y_pos+=y_step, res_pos+=x_res_dim) | ||
133 | INPROD(x_pos,y_pos) | ||
134 | |||
135 | for (; /* RIGHT EDGE */ | ||
136 | x_pos<x_stop; | ||
137 | x_pos+=x_step, base_res_pos++) | ||
138 | { | ||
139 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,0,temp,REDUCE); | ||
140 | for (y_pos=y_ctr_start, res_pos=base_res_pos; | ||
141 | y_pos<y_ctr_stop; | ||
142 | y_pos+=y_step, res_pos+=x_res_dim) | ||
143 | INPROD(x_ctr_stop,y_pos) | ||
144 | } | ||
145 | |||
146 | for (res_pos-=(x_res_dim-1); | ||
147 | y_pos<y_stop; /* BOTTOM ROWS */ | ||
148 | y_pos+=y_step) | ||
149 | { | ||
150 | for (x_pos=x_start; /* BOTTOM-LEFT CORNER */ | ||
151 | x_pos<x_ctr_start; | ||
152 | x_pos+=x_step, res_pos++) | ||
153 | { | ||
154 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-y_ctr_stop+1,temp,REDUCE); | ||
155 | INPROD(0,y_ctr_stop) | ||
156 | } | ||
157 | |||
158 | (*reflect)(filt,x_fdim,y_fdim,0,y_pos-y_ctr_stop+1,temp,REDUCE); | ||
159 | for (; /* BOTTOM EDGE */ | ||
160 | x_pos<x_ctr_stop; | ||
161 | x_pos+=x_step, res_pos++) | ||
162 | INPROD(x_pos,y_ctr_stop) | ||
163 | |||
164 | for (; /* BOTTOM-RIGHT CORNER */ | ||
165 | x_pos<x_stop; | ||
166 | x_pos+=x_step, res_pos++) | ||
167 | { | ||
168 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-y_ctr_stop+1,temp,REDUCE); | ||
169 | INPROD(x_ctr_stop,y_ctr_stop) | ||
170 | } | ||
171 | } /* end BOTTOM */ | ||
172 | return(0); | ||
173 | } /* end of internal_reduce */ | ||
174 | |||
175 | |||
176 | /* | ||
177 | -------------------------------------------------------------------- | ||
178 | Upsample IMAGE according to START,STEP, and STOP parameters and then | ||
179 | convolve with FILT, adding values into RESULT array. IMAGE | ||
180 | dimensions should be ceil((stop-start)/step). See | ||
181 | description of internal_reduce (above). | ||
182 | |||
183 | WARNING: this subroutine destructively modifies the RESULT array! | ||
184 | ------------------------------------------------------------------------ */ | ||
185 | |||
186 | /* abstract out the inner product computation */ | ||
187 | #define INPROD2(XCNR,YCNR) \ | ||
188 | { \ | ||
189 | val = image[im_pos]; \ | ||
190 | for (res_pos=YCNR*x_dim+XCNR, filt_pos=0, x_filt_stop=x_fdim; \ | ||
191 | x_filt_stop<=filt_size; \ | ||
192 | res_pos+=(x_dim-x_fdim), x_filt_stop+=x_fdim) \ | ||
193 | for (; \ | ||
194 | filt_pos<x_filt_stop; \ | ||
195 | filt_pos++, res_pos++) \ | ||
196 | result[res_pos] += val*temp[filt_pos]; \ | ||
197 | } | ||
198 | |||
199 | int internal_expand(image,filt,temp,x_fdim,y_fdim, | ||
200 | x_start,x_step,x_stop,y_start,y_step,y_stop, | ||
201 | result,x_dim,y_dim,edges) | ||
202 | register image_type *result, *temp; | ||
203 | register int x_fdim, x_dim; | ||
204 | register int x_step, y_step; | ||
205 | register image_type *image; | ||
206 | int x_start, y_start; | ||
207 | image_type *filt; | ||
208 | int y_fdim, y_dim; | ||
209 | char *edges; | ||
210 | { | ||
211 | register double val; | ||
212 | register int filt_pos, res_pos, x_filt_stop; | ||
213 | register int x_pos, filt_size = x_fdim*y_fdim; | ||
214 | register int y_pos, im_pos; | ||
215 | register int x_ctr_stop = x_dim - ((x_fdim==1)?0:x_fdim); | ||
216 | int y_ctr_stop = (y_dim - ((y_fdim==1)?0:y_fdim)); | ||
217 | int x_ctr_start = ((x_fdim==1)?0:1); | ||
218 | int y_ctr_start = ((y_fdim==1)?0:1); | ||
219 | int x_fmid = x_fdim/2; | ||
220 | int y_fmid = y_fdim/2; | ||
221 | int base_im_pos, x_im_dim = (x_stop-x_start+x_step-1)/x_step; | ||
222 | fptr reflect = edge_function(edges); /* look up edge-handling function */ | ||
223 | |||
224 | if (!reflect) return(-1); | ||
225 | |||
226 | /* shift start/stop coords to filter upper left hand corner */ | ||
227 | x_start -= x_fmid; y_start -= y_fmid; | ||
228 | x_stop -= x_fmid; y_stop -= y_fmid; | ||
229 | |||
230 | if (x_stop < x_ctr_stop) x_ctr_stop = x_stop; | ||
231 | if (y_stop < y_ctr_stop) y_ctr_stop = y_stop; | ||
232 | |||
233 | for (im_pos=0, y_pos=y_start; /* TOP ROWS */ | ||
234 | y_pos<y_ctr_start; | ||
235 | y_pos+=y_step) | ||
236 | { | ||
237 | for (x_pos=x_start; /* TOP-LEFT CORNER */ | ||
238 | x_pos<x_ctr_start; | ||
239 | x_pos+=x_step, im_pos++) | ||
240 | { | ||
241 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-1,temp,EXPAND); | ||
242 | INPROD2(0,0) | ||
243 | } | ||
244 | |||
245 | (*reflect)(filt,x_fdim,y_fdim,0,y_pos-1,temp,EXPAND); | ||
246 | for (; /* TOP EDGE */ | ||
247 | x_pos<x_ctr_stop; | ||
248 | x_pos+=x_step, im_pos++) | ||
249 | INPROD2(x_pos,0) | ||
250 | |||
251 | for (; /* TOP-RIGHT CORNER */ | ||
252 | x_pos<x_stop; | ||
253 | x_pos+=x_step, im_pos++) | ||
254 | { | ||
255 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-1,temp,EXPAND); | ||
256 | INPROD2(x_ctr_stop,0) | ||
257 | } | ||
258 | } /* end TOP ROWS */ | ||
259 | |||
260 | y_ctr_start = y_pos; /* hold location of top */ | ||
261 | for (base_im_pos=im_pos, x_pos=x_start; /* LEFT EDGE */ | ||
262 | x_pos<x_ctr_start; | ||
263 | x_pos+=x_step, base_im_pos++) | ||
264 | { | ||
265 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,0,temp,EXPAND); | ||
266 | for (y_pos=y_ctr_start, im_pos=base_im_pos; | ||
267 | y_pos<y_ctr_stop; | ||
268 | y_pos+=y_step, im_pos+=x_im_dim) | ||
269 | INPROD2(0,y_pos) | ||
270 | } | ||
271 | |||
272 | (*reflect)(filt,x_fdim,y_fdim,0,0,temp,EXPAND); | ||
273 | for (; /* CENTER */ | ||
274 | x_pos<x_ctr_stop; | ||
275 | x_pos+=x_step, base_im_pos++) | ||
276 | for (y_pos=y_ctr_start, im_pos=base_im_pos; | ||
277 | y_pos<y_ctr_stop; | ||
278 | y_pos+=y_step, im_pos+=x_im_dim) | ||
279 | INPROD2(x_pos,y_pos) | ||
280 | |||
281 | for (; /* RIGHT EDGE */ | ||
282 | x_pos<x_stop; | ||
283 | x_pos+=x_step, base_im_pos++) | ||
284 | { | ||
285 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,0,temp,EXPAND); | ||
286 | for (y_pos=y_ctr_start, im_pos=base_im_pos; | ||
287 | y_pos<y_ctr_stop; | ||
288 | y_pos+=y_step, im_pos+=x_im_dim) | ||
289 | INPROD2(x_ctr_stop,y_pos) | ||
290 | } | ||
291 | |||
292 | for (im_pos-=(x_im_dim-1); | ||
293 | y_pos<y_stop; /* BOTTOM ROWS */ | ||
294 | y_pos+=y_step) | ||
295 | { | ||
296 | for (x_pos=x_start; /* BOTTOM-LEFT CORNER */ | ||
297 | x_pos<x_ctr_start; | ||
298 | x_pos+=x_step, im_pos++) | ||
299 | { | ||
300 | (*reflect)(filt,x_fdim,y_fdim,x_pos-1,y_pos-y_ctr_stop+1,temp,EXPAND); | ||
301 | INPROD2(0,y_ctr_stop) | ||
302 | } | ||
303 | |||
304 | (*reflect)(filt,x_fdim,y_fdim,0,y_pos-y_ctr_stop+1,temp,EXPAND); | ||
305 | for (; /* BOTTOM EDGE */ | ||
306 | x_pos<x_ctr_stop; | ||
307 | x_pos+=x_step, im_pos++) | ||
308 | INPROD2(x_pos,y_ctr_stop) | ||
309 | |||
310 | for (; /* BOTTOM-RIGHT CORNER */ | ||
311 | x_pos<x_stop; | ||
312 | x_pos+=x_step, im_pos++) | ||
313 | { | ||
314 | (*reflect)(filt,x_fdim,y_fdim,x_pos-x_ctr_stop+1,y_pos-y_ctr_stop+1,temp,EXPAND); | ||
315 | INPROD2(x_ctr_stop,y_ctr_stop) | ||
316 | } | ||
317 | } /* end BOTTOM */ | ||
318 | return(0); | ||
319 | } /* end of internal_expand */ | ||
320 | |||
321 | |||
322 | /* Local Variables: */ | ||
323 | /* buffer-read-only: t */ | ||
324 | /* End: */ | ||
325 | |||