-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmexc_Histogram.cpp
95 lines (82 loc) · 2.76 KB
/
mexc_Histogram.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# include <stdio.h>
# include <stdlib.h>
# include "mex.h"
# include "math.h"
# define ROUND(x) (floor((x)+.5))
# define MIN(x, y) ((x)<(y)? (x):(y))
/* Compute pixel index in the vector that stores image */
int px(int x, int y, int lengthx, int lengthy) /* the image is lengthx*lengthy */
{
return (x + (y-1)*lengthx - 1);
}
/* variables */
int numImage, sizex, sizey, numOrient, halfFilterSize, numBin;
float **fI, binSize, *histog, saturation;
/* compute sigmoid transformation */
void SigmoidTransform()
{
int x, y, here, orient, img, i;
for (x=1; x<=sizex; x++)
for (y=1; y<=sizey; y++)
{
here = px(x, y, sizex, sizey);
for (orient=0; orient<numOrient; orient++)
{
for (img=0; img<numImage; img++)
{
i = orient*numImage+img;
fI[i][here] = saturation*(2./(1.+exp(-2.*fI[i][here]/saturation))-1.);
}
}
}
}
/* compute histogram of q() */
void Histogramq()
{
int orient, img, x, y, here, b, tot;
tot = 0;
for (x=halfFilterSize+1; x<sizex-halfFilterSize; x++)
for (y=halfFilterSize+1; y<sizey-halfFilterSize; y++)
{
here = px(x, y, sizex, sizey);
for (orient=0; orient<numOrient; orient++)
{
for (img=0; img<numImage; img++)
{
b = MIN(floor(fI[orient*numImage+img][here]/binSize), numBin-1);
histog[b] += 1.;
tot ++;
}
}
}
for (b=0; b<numBin; b++)
histog[b] /= (binSize*tot);
}
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
int orient, img, c;
mxArray *f;
c = 0;
numImage = ROUND(mxGetScalar(prhs[c++])); /* number of images */
numOrient = ROUND(mxGetScalar(prhs[c++])); /* number of orientations */
fI = (float**)mxCalloc(numImage*numOrient, sizeof(float*)); /* fitered images */
for (img=0; img<numImage; img++)
{
for (orient=0; orient<numOrient; orient++)
{
f = mxGetCell(prhs[c], orient*numImage+img);
fI[orient*numImage+img] = (float*)mxGetPr(f); /* get pointers to filtered images */
}
}
c++;
halfFilterSize = ROUND(mxGetScalar(prhs[c++])); /* half size of filters */
sizex = ROUND(mxGetScalar(prhs[c++]));
sizey = ROUND(mxGetScalar(prhs[c++])); /* size of images */
binSize = mxGetScalar(prhs[c++]); /* size of bin */
numBin = ROUND(mxGetScalar(prhs[c++])); /* number of bins */
histog = (float*)mxGetPr(prhs[c++]); /* histogram of q() */
saturation = mxGetScalar(prhs[c++]); /* saturation level of sigmoid transform */
SigmoidTransform();
Histogramq();
}