I have already passed an image to my mexFunction but now I need to pass an array of images and I am struggling to get the thing right. This is my code to get the simple Image. This works perfectly but when I go into 3D I don t understand how the information is arranged in the mxArray.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
mxArray *matrixIn = prhs[0];
inputImage=(double *)mxGetPr(matrixIn);
int x = int(dims[0]);
int y = int(dims[1]);
volume3D image(inputImage, x, y, 1);
}
volume3D::volume3D(double* image, int x, int y, int z)
{
allocateVolume( x, y, z);
for(int i=0; i<xSize; i++)
for(int j=0; j<ySize; j++) {
volume[i][j][0] = double(image[(i)*x+j]);
}
}
我这样做是为了绕过它。
mwSize mrows,ncols; mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]);
plhs[0] = mxCreateNumericMatrix(mrows, ncols, mxDOUBLE_CLASS, mxREAL);
double *matlabTumorMap = mxGetPr(plhs[0]);
const int * dims = mxGetDimensions( plhs[0]);
int x = int(dims[0]);
int y = int(dims[1]);
int z = int(dims[2]);
mwIndex subs[3];
mexPrintf("x %i
",x);
mexPrintf("y %i
",y);
mexPrintf("z %i
",z);
mxArray *matrixTumor = plhs[0];
for(subs[0]=0; subs[0]<x; subs[0]++)
for(subs[1]=0; subs[1]<y; subs[1]++)
for(subs[2]=0; subs[2]<z; subs[2]++)
{
mwIndex x = mxCalcSingleSubscript( matrixTumor,3,subs);
matlabTumorMap[x] = tumorMap.getVoxel(subs[0],subs[1],subs[2]);
}