MATLAB: How Matlab coder convert the image to unsinged char

ccodecdigital image processingimage processingImage Processing ToolboxMATLABmatlab coder

good day
I am working with matlab Coder which convert a image function to c++ code. the function looks something like this array=findsomething(I); where I is an image has been read with the function Imread. the result code in c++ code which has emxArray_uint8_T which looks like this struct emxArray_uint8_T { unsigned char *data; int *size; int allocatedSize; int numDimensions; boolean_T canFreeData; }; the data from the image should be a stream in unsigned char *data,i can read an image from OpenCV but i need to convert the image type from Mat to unsighed char, i have already read http://www.mathworks.com/help/matlab/matlab_external/matlab-data.html#f22019 but i dont know which comes first red blue or green,and if red should i start with coloms or rows? can someone help

Best Answer

so i found out how to fill this emxArray_uint8_T with unsinged char, in c++ there is the code
emxArray_uint8_T *I;
emxInit_uint8_T(&I, 3);
string imageName("F:/********amr.jpg");
Mat image;
image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file
Vec3b intensity;
int sizeimage, counter;
int rows = image.rows;
int cols = image.cols;
sizeimage = rows*cols;
I->size[0] = rows;
I->size[1] = cols;
I->size[2] = 3;
emxEnsureCapacity((emxArray__common *)I, 0, (int)sizeof(unsigned char));
counter = 0;
for (int i = 0;i < cols;i++)
{
for (int j = 0;j < rows;j++)
{
intensity = image.at<Vec3b>(j, i);
uchar blue = intensity.val[0];
uchar green = intensity.val[1];
uchar red = intensity.val[2];
I->data[counter] = red;
I->data[counter + sizeimage] = green;
I->data[counter + 2* sizeimage] = blue;
counter++;
}
}
now the data is transfered from the image into the emxArray_uint8_T which u can use in your c++ code i had the same results of my function in Matlab and my c++ program.