Borrar filtros
Borrar filtros

pixel data from mex to matlab: mxArray definition..

1 visualización (últimos 30 días)
Enrico  Boscolo
Enrico Boscolo el 29 de Jun. de 2015
Comentada: Enrico Boscolo el 2 de Jul. de 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

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 29 de Jun. de 2015
Editada: Titus Edelhofer el 30 de Jun. de 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 comentarios
Titus Edelhofer
Titus Edelhofer el 30 de Jun. de 2015
Yes, of course, I mixed this up. I updated the answer. Thanks James!
Enrico  Boscolo
Enrico Boscolo el 2 de Jul. de 2015
very helpful !!..it's working. Many thanks Enrico

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by