diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/wrap.c')
| -rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/wrap.c | 281 |
1 files changed, 0 insertions, 281 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/wrap.c b/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/wrap.c deleted file mode 100755 index a081123..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/wrap.c +++ /dev/null | |||
| @@ -1,281 +0,0 @@ | |||
| 1 | /* | ||
| 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 3 | ;;; File: wrap.c | ||
| 4 | ;;; Author: Eero Simoncelli | ||
| 5 | ;;; Description: Circular convolution on 2D images. | ||
| 6 | ;;; Creation Date: Spring, 1987. | ||
| 7 | ;;; MODIFICATIONS: | ||
| 8 | ;;; 6/96: Switched array types to double float. | ||
| 9 | ;;; 2/97: made more robust and readable. Added STOP arguments. | ||
| 10 | ;;; ---------------------------------------------------------------- | ||
| 11 | ;;; Object-Based Vision and Image Understanding System (OBVIUS), | ||
| 12 | ;;; Copyright 1988, Vision Science Group, Media Laboratory, | ||
| 13 | ;;; Massachusetts Institute of Technology. | ||
| 14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdlib.h> | ||
| 18 | |||
| 19 | #include "convolve.h" | ||
| 20 | |||
| 21 | /* | ||
| 22 | -------------------------------------------------------------------- | ||
| 23 | Performs correlation (i.e., convolution with filt(-x,-y)) of FILT | ||
| 24 | with IMAGE followed by subsampling (a.k.a. REDUCE in Burt&Adelson81). | ||
| 25 | The operations are combined to avoid unnecessary computation of the | ||
| 26 | convolution samples that are to be discarded in the subsampling | ||
| 27 | operation. The convolution is done in 9 sections so that mod | ||
| 28 | operations are not performed unnecessarily. The subsampling lattice | ||
| 29 | is specified by the START, STEP and STOP parameters. | ||
| 30 | -------------------------------------------------------------------- */ | ||
| 31 | |||
| 32 | /* abstract out the inner product computation */ | ||
| 33 | #define INPROD(YSTART,YIND,XSTART,XIND) \ | ||
| 34 | { \ | ||
| 35 | sum=0.0; \ | ||
| 36 | for (y_im=YSTART, filt_pos=0, x_filt_stop=x_fdim; \ | ||
| 37 | x_filt_stop<=filt_size; \ | ||
| 38 | y_im++, x_filt_stop+=x_fdim) \ | ||
| 39 | for (x_im=XSTART ; \ | ||
| 40 | filt_pos<x_filt_stop; \ | ||
| 41 | filt_pos++, x_im++) \ | ||
| 42 | sum += imval[YIND][XIND] * filt[filt_pos]; \ | ||
| 43 | result[res_pos] = sum; \ | ||
| 44 | } | ||
| 45 | |||
| 46 | int internal_wrap_reduce(image, x_dim, y_dim, filt, x_fdim, y_fdim, | ||
| 47 | x_start, x_step, x_stop, y_start, y_step, y_stop, | ||
| 48 | result) | ||
| 49 | register image_type *filt, *result; | ||
| 50 | register int x_dim, y_dim, x_fdim, y_fdim; | ||
| 51 | image_type *image; | ||
| 52 | int x_start, x_step, x_stop, y_start, y_step, y_stop; | ||
| 53 | { | ||
| 54 | register double sum; | ||
| 55 | register int filt_size = x_fdim*y_fdim; | ||
| 56 | image_type **imval; | ||
| 57 | register int filt_pos, x_im, y_im, x_filt_stop; | ||
| 58 | register int x_pos, y_pos, res_pos; | ||
| 59 | int x_ctr_stop = x_dim - x_fdim + 1; | ||
| 60 | int y_ctr_stop = y_dim - y_fdim + 1; | ||
| 61 | int x_ctr_start = 0; | ||
| 62 | int y_ctr_start = 0; | ||
| 63 | int x_fmid = x_fdim/2; | ||
| 64 | int y_fmid = y_fdim/2; | ||
| 65 | |||
| 66 | /* shift start/stop coords to filter upper left hand corner */ | ||
| 67 | x_start -= x_fmid; y_start -= y_fmid; | ||
| 68 | x_stop -= x_fmid; y_stop -= y_fmid; | ||
| 69 | |||
| 70 | if (x_stop < x_ctr_stop) x_ctr_stop = x_stop; | ||
| 71 | if (y_stop < y_ctr_stop) y_ctr_stop = y_stop; | ||
| 72 | |||
| 73 | /* Set up pointer array for rows */ | ||
| 74 | imval = (image_type **) malloc(y_dim*sizeof(image_type *)); | ||
| 75 | if (imval IS NULL) | ||
| 76 | { | ||
| 77 | printf("INTERNAL_WRAP: Failed to allocate temp array!"); | ||
| 78 | return(-1); | ||
| 79 | } | ||
| 80 | for (y_pos=y_im=0;y_pos<y_dim;y_pos++,y_im+=x_dim) | ||
| 81 | imval[y_pos] = (image+y_im); | ||
| 82 | |||
| 83 | for (res_pos=0, y_pos=y_start; /* TOP ROWS */ | ||
| 84 | y_pos<y_ctr_start; | ||
| 85 | y_pos+=y_step) | ||
| 86 | { | ||
| 87 | for (x_pos=x_start; | ||
| 88 | x_pos<x_ctr_start; | ||
| 89 | x_pos+=x_step, res_pos++) | ||
| 90 | INPROD(y_pos+y_dim, y_im%y_dim, x_pos+x_dim, x_im%x_dim) | ||
| 91 | |||
| 92 | for (; | ||
| 93 | x_pos<x_ctr_stop; | ||
| 94 | x_pos+=x_step, res_pos++) | ||
| 95 | INPROD(y_pos+y_dim, y_im%y_dim, x_pos, x_im) | ||
| 96 | |||
| 97 | for (; | ||
| 98 | x_pos<x_stop; | ||
| 99 | x_pos+=x_step, res_pos++) | ||
| 100 | INPROD(y_pos+y_dim, y_im%y_dim, x_pos, x_im%x_dim) | ||
| 101 | } /* end TOP ROWS */ | ||
| 102 | |||
| 103 | for (; /* MID ROWS */ | ||
| 104 | y_pos<y_ctr_stop; | ||
| 105 | y_pos+=y_step) | ||
| 106 | { | ||
| 107 | for (x_pos=x_start; | ||
| 108 | x_pos<x_ctr_start; | ||
| 109 | x_pos+=x_step, res_pos++) | ||
| 110 | INPROD(y_pos, y_im, x_pos+x_dim, x_im%x_dim) | ||
| 111 | |||
| 112 | for (; /* CENTER SECTION */ | ||
| 113 | x_pos<x_ctr_stop; | ||
| 114 | x_pos+=x_step, res_pos++) | ||
| 115 | INPROD(y_pos, y_im, x_pos, x_im) | ||
| 116 | |||
| 117 | for (; | ||
| 118 | x_pos<x_stop; | ||
| 119 | x_pos+=x_step, res_pos++) | ||
| 120 | INPROD(y_pos, y_im, x_pos, x_im%x_dim) | ||
| 121 | } /* end MID ROWS */ | ||
| 122 | |||
| 123 | for (; /* BOTTOM ROWS */ | ||
| 124 | y_pos<y_stop; | ||
| 125 | y_pos+=y_step) | ||
| 126 | { | ||
| 127 | for (x_pos=x_start; | ||
| 128 | x_pos<x_ctr_start; | ||
| 129 | x_pos+=x_step, res_pos++) | ||
| 130 | INPROD(y_pos, y_im%y_dim, x_pos+x_dim, x_im%x_dim) | ||
| 131 | |||
| 132 | for (; | ||
| 133 | x_pos<x_ctr_stop; | ||
| 134 | x_pos+=x_step, res_pos++) | ||
| 135 | INPROD(y_pos, y_im%y_dim, x_pos, x_im) | ||
| 136 | |||
| 137 | for (; | ||
| 138 | x_pos<x_stop; | ||
| 139 | x_pos+=x_step, res_pos++) | ||
| 140 | INPROD(y_pos, y_im%y_dim, x_pos, x_im%x_dim) | ||
| 141 | } /* end BOTTOM ROWS */ | ||
| 142 | |||
| 143 | free ((image_type **) imval); | ||
| 144 | |||
| 145 | return(0); | ||
| 146 | } /* end of internal_wrap_reduce */ | ||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | /* | ||
| 151 | -------------------------------------------------------------------- | ||
| 152 | Performs upsampling (padding with zeros) followed by convolution of | ||
| 153 | FILT with IMAGE (a.k.a. EXPAND in Burt&Adelson81). The operations | ||
| 154 | are combined to avoid unnecessary multiplication of filter samples | ||
| 155 | with zeros in the upsampled image. The convolution is done in 9 | ||
| 156 | sections so that mod operation is not performed unnecessarily. | ||
| 157 | Arguments are described in the comment above internal_wrap_reduce. | ||
| 158 | |||
| 159 | WARNING: this subroutine destructively modifes the RESULT image, so | ||
| 160 | the user must zero the result before invocation! | ||
| 161 | -------------------------------------------------------------------- */ | ||
| 162 | |||
| 163 | /* abstract out the inner product computation */ | ||
| 164 | #define INPROD2(YSTART,YIND,XSTART,XIND) \ | ||
| 165 | { \ | ||
| 166 | val = image[im_pos]; \ | ||
| 167 | for (y_res=YSTART, filt_pos=0, x_filt_stop=x_fdim; \ | ||
| 168 | x_filt_stop<=filt_size; \ | ||
| 169 | y_res++, x_filt_stop+=x_fdim) \ | ||
| 170 | for (x_res=XSTART; \ | ||
| 171 | filt_pos<x_filt_stop; \ | ||
| 172 | filt_pos++, x_res++) \ | ||
| 173 | imval[YIND][XIND] += val * filt[filt_pos]; \ | ||
| 174 | } | ||
| 175 | |||
| 176 | int internal_wrap_expand(image, filt, x_fdim, y_fdim, | ||
| 177 | x_start, x_step, x_stop, y_start, y_step, y_stop, | ||
| 178 | result, x_dim, y_dim) | ||
| 179 | register image_type *filt, *result; | ||
| 180 | register int x_fdim, y_fdim, x_dim, y_dim; | ||
| 181 | image_type *image; | ||
| 182 | int x_start, x_step, x_stop, y_start, y_step, y_stop; | ||
| 183 | { | ||
| 184 | register double val; | ||
