-
Notifications
You must be signed in to change notification settings - Fork 0
/
f12to16bits.cpp
37 lines (31 loc) · 883 Bytes
/
f12to16bits.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
#include <matrix.h>
#include <math.h>
#include <mex.h>
int coord(int m, int n, int rows){
return n * rows + m;
}
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
unsigned short int *img12bits, *img16bits;
int cols, rows, n, m;
/*if (!mxIsDouble(F_ARG))
{
mexErrMsgTxt("Input data should be double. \n");
}*/
/* input */
cols = mxGetN(prhs[0]);
rows = mxGetM(prhs[0]);
img12bits = (unsigned short int*) mxGetPr(prhs[0]);
/* output */
plhs[0] = mxCreateNumericMatrix(rows, cols, mxUINT16_CLASS, mxREAL);
img16bits = (unsigned short int*) mxGetData(plhs[0]);
for(m = 0; m < rows; m++)
{
for(n = 0; n < cols; n++)
{
img16bits[coord(m, n, rows)] = img12bits[coord(m, n, rows)] * 16;
}
}
return;
}