summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c')
-rwxr-xr-xSD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c140
1 files changed, 0 insertions, 140 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c b/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c
deleted file mode 100755
index 43a99c7..0000000
--- a/SD-VBS/benchmarks/texture_synthesis/src/matlab/MEX/histo.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/*
2[N, X] = histo(MTX, NBINS_OR_BINSIZE, BIN_CENTER)
3 >>> See histo.m for documentation <<<
4 EPS, ported from OBVIUS, 3/97.
5*/
6
7#define V4_COMPAT
8#include <matrix.h> /* Matlab matrices */
9#include <mex.h>
10
11#include <stddef.h> /* NULL */
12#include <math.h> /* ceil */
13
14#define notDblMtx(it) (!mxIsNumeric(it) || !mxIsDouble(it) || mxIsSparse(it) || mxIsComplex(it))
15
16#define PAD 0.49999 /* A hair below 1/2, to avoid roundoff errors */
17#define MAXBINS 20000
18
19void mexFunction(int nlhs, /* Num return vals on lhs */
20 mxArray *plhs[], /* Matrices on lhs */
21 int nrhs, /* Num args on rhs */
22 const mxArray *prhs[] /* Matrices on rhs */
23 )
24 {
25 register double temp;
26 register int binnum, i, size;
27 register double *im, binsize;
28 register double origin, *hist, mn, mx, mean;
29 register int nbins;
30 double *bincenters;
31 mxArray *arg;
32 double *mxMat;
33
34 if (nrhs < 1 ) mexErrMsgTxt("requires at least 1 argument.");
35
36 /* ARG 1: MATRIX */
37 arg = prhs[0];
38 if notDblMtx(arg) mexErrMsgTxt("MTX arg must be a real non-sparse matrix.");
39 im = mxGetPr(arg);
40 size = (int) mxGetM(arg) * mxGetN(arg);
41
42 /* FIND min, max, mean values of MTX */
43 mn = *im; mx = *im; binsize = 0;
44 for (i=1; i<size; i++)
45 {
46 temp = im[i];
47 if (temp < mn)
48 mn = temp;
49 else if (temp > mx)
50 mx = temp;
51 binsize += temp;
52 }
53 mean = binsize / size;
54
55 /* ARG 3: BIN_CENTER */
56 if (nrhs > 2)
57 {
58 arg = prhs[2];
59 if notDblMtx(arg) mexErrMsgTxt("BIN_CENTER arg must be a real scalar.");
60 if (mxGetM(arg) * mxGetN(arg) != 1)
61 mexErrMsgTxt("BIN_CENTER must be a real scalar.");
62 mxMat= mxGetPr(arg);
63 origin = *mxMat;
64 }
65 else
66 origin = mean;
67
68 /* ARG 2: If positive, NBINS. If negative, -BINSIZE. */
69 if (nrhs > 1)
70 {
71 arg = prhs[1];
72 if notDblMtx(arg) mexErrMsgTxt("NBINS_OR_BINSIZE arg must be a real scalar.");
73 if (mxGetM(arg) * mxGetN(arg) != 1)
74 mexErrMsgTxt("NBINS_OR_BINSIZE must be a real scalar.");
75 mxMat= mxGetPr(arg);
76 binsize = *mxMat;
77 }
78 else
79 {
80 binsize = 101; /* DEFAULT: 101 bins */
81 }
82
83 /* --------------------------------------------------
84 Adjust origin, binsize, nbins such that
85 mx <= origin + (nbins-1)*binsize + PAD*binsize
86 mn >= origin - PAD*binsize
87 -------------------------------------------------- */
88 if (binsize < 0) /* user specified BINSIZE */
89 {
90 binsize = -binsize;
91 origin -= binsize * ceil((origin-mn-PAD*binsize)/binsize);
92 nbins = (int) ceil((mx-origin-PAD*binsize)/binsize) + 1;
93 }
94 else /* user specified NBINS */
95 {
96 nbins = (int) (binsize + 0.5); /* round to int */
97 if (nbins == 0)
98 mexErrMsgTxt("NBINS must be greater than zero.");
99 binsize = (mx-mn)/(nbins-1+2*PAD); /* start with lower bound */
100 i = ceil((origin-mn-binsize/2)/binsize);
101 if ( mn < (origin-i*binsize-PAD*binsize) )
102 binsize = (origin-mn)/(i+PAD);
103 else if ( mx > (origin+(nbins-1-i)*binsize+PAD*binsize) )
104 binsize = (mx-origin)/((nbins-1-i)+PAD);
105 origin -= binsize * ceil((origin-mn-PAD*binsize)/binsize);
106 }
107
108 if (nbins > MAXBINS)
109 {
110 mexPrintf("nbins: %d, MAXBINS: %d\n",nbins,MAXBINS);
111 mexErrMsgTxt("Number of histo bins has exceeded maximum");
112 }
113
114 /* Allocate hist and xvals */
115 plhs[0] = (mxArray *) mxCreateDoubleMatrix(1,nbins,mxREAL);
116 if (plhs[0] == NULL) mexErrMsgTxt("Error allocating result matrix");
117 hist = mxGetPr(plhs[0]);
118
119 if (nlhs > 1)
120 {
121 plhs[1] = (mxArray *) mxCreateDoubleMatrix(1,nbins,mxREAL);
122 if (plhs[1] == NULL) mexErrMsgTxt("Error allocating result matrix");
123 bincenters = mxGetPr(plhs[1]);
124 for (i=0, temp=origin; i<nbins; i++, temp+=binsize)
125 bincenters[i] = temp;
126 }
127
128 for (i=0; i<size; i++)
129 {
130 binnum = (int) ((im[i] - origin)/binsize + 0.5);
131 if ((binnum < nbins) && (binnum >= 0))
132 (hist[binnum]) += 1.0;
133 else
134 printf("HISTO warning: value %f outside of range [%f,%f]\n",
135 im[i], origin-0.5*binsize, origin+(nbins-0.5)*binsize);
136 }
137
138 return;
139 }
140