-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContrastAccumulatedHistogram.c
64 lines (55 loc) · 1.33 KB
/
ContrastAccumulatedHistogram.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <math.h>
#include "mex.h"
void ScaledHistDouble(double *a,
double *g,
int n,
int length,
double *y);
void ScaledHistDouble(double *a,
double *g,
int n,
int length,
double *y) {
int i;
double scale;
double z, _g;
scale = (double) (n-1);
for (i = 0; i < length; i++) {
z = floor(a[i] * scale + .5);
_g = g[i];
if (z < 0.0) {
y[0] += _g;
} else if (z > (n-1)) {
y[n-1] += _g;
} else {
y[(int) z] += _g;
}
}
}
void mexFunction(int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
{
int length;
const mxArray *A;
const mxArray *G;
double n_real;
int n;
double *a_real;
double *g_real;
double *y;
mxArray *Y;
A = prhs[0];
G = prhs[1];
n_real = *((double *) mxGetPr(prhs[2]));
n = (int) n_real;
length = mxGetM(A) * mxGetN(A);
Y = mxCreateDoubleMatrix(n, 1, mxREAL);
y = (double *) mxGetPr(Y);
a_real = (double *) mxGetPr(A);
g_real = (double *) mxGetPr(G);
ScaledHistDouble(a_real, g_real, n, length, y);
/* Done! Give the answer back */
plhs[0] = Y;
}