pixel data from mex to matlab: mxArray definition..

1 Ansicht (letzte 30 Tage)
Enrico  Boscolo
Enrico Boscolo am 29 Jun. 2015
Kommentiert: Enrico Boscolo am 2 Jul. 2015
Hello I’m trying to use TCP/IP gEth. camera using mex file. The cpp code provides by camera vendor is very useful to open library/open/close camera and trigger, also I’m able to save image bmp in a selected folder from where I can read the image (1600X1200) from matlab (imread/imshow). Everything works fine but I’m not able to transfer the pixel data from mex to matlab. Below an example of the cpp code where a simple pixel calculation is performed (*pPixel = ~*pPixel): // get the pointer to the image data
void* pData = NULL;
int32_t iImageOffset = 0;
pBuffer->GetPtr (LvBuffer_UniBase, &pData);
pBuffer->GetInt32 (LvBuffer_UniImageOffset, &iImageOffset);
pData = (uint8_t*)pData + iImageOffset;
for (int32_t j=0; j<(1200); j++)
{
uint8_t* pPixel = ((uint8_t*)pData) + j*1600;
for (int32_t i=0; i<(1600); i++)
{
for (int32_t k=0; k<iBytesPerPixel; k++)
{
*pPixel = ~*pPixel;
pPixel++;
}
}
}
My problem is how to transfer the pPixel (uint_8) to matlab… I’m tring to use mxArray B; B= mxCreateNumericData(1600, 1200, mxINT8_CLASS, mxREAL); But I don’t know how to populate the matrix B. Please, any advices??
M. Thanks
Enrico

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 29 Jun. 2015
Bearbeitet: Titus Edelhofer am 30 Jun. 2015
Hi Enrico,
as a .bmp it probably has 24 bits, i.e., you iBytesPerPixel is 3. Therefore you should allocate a 1600x1200x3 matrix:
mwSize aSize[3] = {1600, 1200, 3};
plhs[0] = mxCreateNumericArray(3, aSize, mxUINT8_CLASS, mxREAL);
uint8_t *pData = (uint8_t*) mxGetData(plhs[0]);
You might use the code you have above to loop on the indices, and put each pixel from pPixel into pData. Note though, that the indices are running differently in MATLAB then in your code, it should be something like
pData[k*1200*1600 + j*1600 + i] = *pPixel;
but I'm not 100% sure I admit ;-).
Titus
  3 Kommentare
Titus Edelhofer
Titus Edelhofer am 30 Jun. 2015
Yes, of course, I mixed this up. I updated the answer. Thanks James!
Enrico  Boscolo
Enrico Boscolo am 2 Jul. 2015
very helpful !!..it's working. Many thanks Enrico

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by