diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/MEX/upConv.c')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/MEX/upConv.c | 195 |
1 files changed, 0 insertions, 195 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/MEX/upConv.c b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/MEX/upConv.c deleted file mode 100755 index 3708f8a..0000000 --- a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/MEX/upConv.c +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | /* | ||
2 | RES = upConv(IM, FILT, EDGES, STEP, START, STOP, RES); | ||
3 | >>> See upConv.m for documentation <<< | ||
4 | This is a matlab interface to the internal_expand function. | ||
5 | EPS, 7/96. | ||
6 | */ | ||
7 | |||
8 | #define V4_COMPAT | ||
9 | #include <matrix.h> /* Matlab matrices */ | ||
10 | #include <mex.h> | ||
11 | |||
12 | #include "convolve.h" | ||
13 | |||
14 | #define notDblMtx(it) (!mxIsNumeric(it) || !mxIsDouble(it) || mxIsSparse(it) || mxIsComplex(it)) | ||
15 | |||
16 | void mexFunction(int nlhs, /* Num return vals on lhs */ | ||
17 | mxArray *plhs[], /* Matrices on lhs */ | ||
18 | int nrhs, /* Num args on rhs */ | ||
19 | const mxArray *prhs[] /* Matrices on rhs */ | ||
20 | ) | ||
21 | { | ||
22 | double *image,*filt, *temp, *result, *orig_filt; | ||
23 | int x_fdim, y_fdim, x_idim, y_idim; | ||
24 | int orig_x = 0, orig_y, x, y; | ||
25 | int x_rdim, y_rdim; | ||
26 | int x_start = 1; | ||
27 | int x_step = 1; | ||
28 | int y_start = 1; | ||
29 | int y_step = 1; | ||
30 | int x_stop, y_stop; | ||
31 | mxArray *arg; | ||
32 | double *mxMat; | ||
33 | char edges[15] = "reflect1"; | ||
34 | |||
35 | if (nrhs<2) mexErrMsgTxt("requres at least 2 args."); | ||
36 | |||
37 | /* ARG 1: IMAGE */ | ||
38 | arg = prhs[0]; | ||
39 | if notDblMtx(arg) mexErrMsgTxt("IMAGE arg must be a non-sparse double float matrix."); | ||
40 | image = mxGetPr(arg); | ||
41 | x_idim = (int) mxGetM(arg); /* X is inner index! */ | ||
42 | y_idim = (int) mxGetN(arg); | ||
43 | |||
44 | /* ARG 2: FILTER */ | ||
45 | arg = prhs[1]; | ||
46 | if notDblMtx(arg) mexErrMsgTxt("FILTER arg must be non-sparse double float matrix."); filt = mxGetPr(arg); | ||
47 | x_fdim = (int) mxGetM(arg); | ||
48 | y_fdim = (int) mxGetN(arg); | ||
49 | |||
50 | /* ARG 3 (optional): EDGES */ | ||
51 | if (nrhs>2) | ||
52 | { | ||
53 | if (!mxIsChar(prhs[2])) | ||
54 | mexErrMsgTxt("EDGES arg must be a string."); | ||
55 | mxGetString(prhs[2],edges,15); | ||
56 | } | ||
57 | |||
58 | /* ARG 4 (optional): STEP */ | ||
59 | if (nrhs>3) | ||
60 | { | ||
61 | arg = prhs[3]; | ||
62 | if notDblMtx(arg) mexErrMsgTxt("STEP arg must be double float matrix."); | ||
63 | if (mxGetM(arg) * mxGetN(arg) != 2) | ||
64 | mexErrMsgTxt("STEP arg must contain two elements."); | ||
65 | mxMat = mxGetPr(arg); | ||
66 | x_step = (int) mxMat[0]; | ||
67 | y_step = (int) mxMat[1]; | ||
68 | if ((x_step<1) || (y_step<1)) | ||
69 | mexErrMsgTxt("STEP values must be greater than zero."); | ||
70 | } | ||
71 | |||
72 | /* ARG 5 (optional): START */ | ||
73 | if (nrhs>4) | ||
74 | { | ||
75 | arg = prhs[4]; | ||
76 | if notDblMtx(arg) mexErrMsgTxt("START arg must be double float matrix."); | ||
77 | if (mxGetM(arg) * mxGetN(arg) != 2) | ||
78 | mexErrMsgTxt("START arg must contain two elements."); | ||
79 | mxMat = mxGetPr(arg); | ||
80 | x_start = (int) mxMat[0]; | ||
81 | y_start = (int) mxMat[1]; | ||
82 | if ((x_start<1) || (y_start<1)) | ||
83 | mexErrMsgTxt("START values must be greater than zero."); | ||
84 | } | ||
85 | x_start--; /* convert to standard C indexes */ | ||
86 | y_start--; | ||
87 | |||
88 | /* ARG 6 (optional): STOP */ | ||
89 | if (nrhs>5) | ||
90 | { | ||
91 | if notDblMtx(prhs[5]) mexErrMsgTxt("STOP arg must be double float matrix."); | ||
92 | if (mxGetM(prhs[5]) * mxGetN(prhs[5]) != 2) | ||
93 | mexErrMsgTxt("STOP arg must contain two elements."); | ||
94 | mxMat = mxGetPr(prhs[5]); | ||
95 | x_stop = (int) mxMat[0]; | ||
96 | y_stop = (int) mxMat[1]; | ||
97 | if ((x_stop<x_start) || (y_stop<y_start)) | ||
98 | mexErrMsgTxt("STOP values must be greater than START values."); | ||
99 | } | ||
100 | else | ||
101 | { /* default: make res dims a multiple of STEP size */ | ||
102 | x_stop = x_step * ((x_start/x_step) + x_idim); | ||
103 | y_stop = y_step * ((y_start/y_step) + y_idim); | ||
104 | } | ||
105 | |||
106 | /* ARG 6 (optional): RESULT image */ | ||
107 | if (nrhs>6) | ||
108 | { | ||
109 | arg = prhs[6]; | ||
110 | if notDblMtx(arg) mexErrMsgTxt("RES arg must be double float matrix."); | ||
111 | |||
112 | /* 7/10/97: Returning one of the args causes problems with Matlab's memory | ||
113 | manager, so we don't return anything if the result image is passed */ | ||
114 | /* plhs[0] = arg; */ | ||
115 | result = mxGetPr(arg); | ||
116 | x_rdim = (int) mxGetM(arg); /* X is inner index! */ | ||
117 | y_rdim = (int) mxGetN(arg); | ||
118 | if ((x_stop>x_rdim) || (y_stop>y_rdim)) | ||
119 | mexErrMsgTxt("STOP values must within image dimensions."); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | x_rdim = x_stop; | ||
124 | y_rdim = y_stop; | ||
125 | /* x_rdim = x_step * ((x_stop+x_step-1)/x_step); | ||
126 | y_rdim = y_step * ((y_stop+y_step-1)/y_step); */ | ||
127 | |||
128 | plhs[0] = (mxArray *) mxCreateDoubleMatrix(x_rdim,y_rdim,mxREAL); | ||
129 | if (plhs[0] == NULL) mexErrMsgTxt("Cannot allocate result matrix"); | ||
130 | result = mxGetPr(plhs[0]); | ||
131 | } | ||
132 | |||
133 | if ( (((x_stop-x_start+x_step-1) / x_step) != x_idim) || | ||
134 | (((y_stop-y_start+y_step-1) / y_step) != y_idim) ) | ||
135 | { | ||
136 | mexPrintf("Im dims: [%d %d]\n",x_idim,y_idim); | ||
137 | mexPrintf("Start: [%d %d]\n",x_start,y_start); | ||
138 | mexPrintf("Step: [%d %d]\n",x_step,y_step); | ||
139 | mexPrintf("Stop: [%d %d]\n",x_stop,y_stop); | ||
140 | mexPrintf("Res dims: [%d %d]\n",x_rdim,y_rdim); | ||
141 | mexErrMsgTxt("Image sizes and upsampling args are incompatible!"); | ||
142 | } | ||
143 | |||
144 | /* upConv has a bug for even-length kernels when using the | ||
145 | reflect1, extend, or repeat edge-handlers */ | ||
146 | if ((!strcmp(edges,"reflect1") || !strcmp(edges,"extend") || !strcmp(edges,"repeat")) | ||
147 | && | ||
148 | ((x_fdim%2 == 0) || (y_fdim%2 == 0))) | ||
149 | { | ||
150 | orig_filt = filt; | ||
151 | orig_x = x_fdim; | ||
152 | orig_y = y_fdim; | ||
153 | x_fdim = 2*(orig_x/2)+1; | ||
154 | y_fdim = 2*(orig_y/2)+1; | ||
155 | filt = mxCalloc(x_fdim*y_fdim, sizeof(double)); | ||
156 | if (filt == NULL) | ||
157 | mexErrMsgTxt("Cannot allocate necessary temporary space"); | ||
158 | for (y=0; y<orig_y; y++) | ||
159 | for (x=0; x<orig_x; x++) | ||
160 | filt[y*x_fdim + x] = orig_filt[y*orig_x + x]; | ||
161 | } | ||
162 | |||
163 | if ((x_fdim > x_rdim) || (y_fdim > y_rdim)) | ||
164 | { | ||
165 | mexPrintf("Filter: [%d %d], ",x_fdim,y_fdim); | ||
166 | mexPrintf("Result: [%d %d]\n",x_rdim,y_rdim); | ||
167 | mexErrMsgTxt("FILTER dimensions larger than RESULT dimensions."); | ||
168 | } | ||
169 | |||
170 | temp = mxCalloc(x_fdim*y_fdim, sizeof(double)); | ||
171 | if (temp == NULL) | ||
172 | mexErrMsgTxt("Cannot allocate necessary temporary space"); | ||
173 | |||
174 | /* | ||
175 | printf("(%d, %d), (%d, %d), (%d, %d), (%d, %d), (%d, %d), %s\n", | ||
176 | x_idim,y_idim,x_fdim,y_fdim,x_rdim,y_rdim, | ||
177 | x_start,x_step,y_start,y_step,edges); | ||
178 | */ | ||
179 | |||
180 | if (strcmp(edges,"circular") == 0) | ||
181 | internal_wrap_expand(image, filt, x_fdim, y_fdim, | ||
182 | x_start, x_step, x_stop, y_start, y_step, y_stop, | ||
183 | result, x_rdim, y_rdim); | ||
184 | else internal_expand(image, filt, temp, x_fdim, y_fdim, | ||
185 | x_start, x_step, x_stop, y_start, y_step, y_stop, | ||
186 | result, x_rdim, y_rdim, edges); | ||
187 | |||
188 | if (orig_x) mxFree((char *) filt); | ||
189 | mxFree((char *) temp); | ||
190 | |||
191 | return; | ||
192 | } | ||
193 | |||
194 | |||
195 | |||