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 | ||
