Passing byte array to Matlab as if read by imread
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
dpb
am 2 Okt. 2013
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 Kommentare
Weitere Antworten (1)
Ashish Uthama
am 2 Okt. 2013
Bearbeitet: Ashish Uthama
am 2 Okt. 2013
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 Kommentare
dpb
am 2 Okt. 2013
Bearbeitet: dpb
am 2 Okt. 2013
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.
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!