Passing byte array to Matlab as if read by imread
조회 수: 6 (최근 30일)
이전 댓글 표시
Possibly a very naive question, so please excuse me if so...
We are wrapping some Matlab functions in a C-callable DLL. The calling application already has images (as bitmap) loaded into memory (as byte arrays). I want to pass an image (as a byte array) to my exported Matlab function so that it can continue to use it internally as if it was read from imread(). How is this done?
So basically:
im = imread('c:\myimage.jpg')
I want to pass 'im' into my Matlab function from C/C++ (I don't want to have to save the bytes to disk and load them using imread since I already have them all in memory). Is simply passing in the raw bytes in mxArray good enough (including the image header bytes)?
댓글 수: 0
채택된 답변
dpb
2013년 10월 2일
That's all there is -- there's no header info returned by imread
Presuming the image format is one w/ 8-bit or less resolution then the return is uint8 otherwise of course it's uint16.
Whether that's "good enough" on the C side all depends on what it needs/expects. If you need the data that's in the header; it'll have to be handled on its own; this wouldn't/won't get it there.
댓글 수: 0
추가 답변 (1개)
Ashish Uthama
2013년 10월 2일
편집: Ashish Uthama
2013년 10월 2일
I assume you are using the MATLAB compiler to wrap MATLAB functions into a C-callable DLL. Have a look at this example which shows how to create an mxArray from C data and pass to the DLL.
In your example, the variable im will have decompressed image as an array. So, yes, creating an mxArray should be good enough provided what you say is a 'byte array' contains the decompressed image. (I did not get what you mean by 'image header bytes'.)
댓글 수: 2
dpb
2013년 10월 2일
편집: dpb
2013년 10월 2일
No. As said above, imread returns only the actual image data; any header information stored in the image file on disk is not in the returned array.
doc imread % for details
Also as said above, what you need/expect on the C side will be totally determined by what your C function is trying to do with the image data.
ADDENDUM:
Oh, on rereading I see I was speaking backwards -- was thinking you were loading in Matlab and passing to C instead of vice versa.
In the latter case, then it depends on what your C function is reading -- if it's only the image data w/o the header, that's what is equivalent to the return from imread.
NB however: the internal storage order in C is row-major whereas it is column-major in Matlab. Hence unless you do the rearrangement the interpretation will be the transpose.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!