how to input to "imread" using uint8 vector that is equivalent to binary data of image file from fread

13 ビュー (過去 30 日間)
Hi, I am trying to read many 512x512 jpg files that extracted from a .db database as uint8 vector for each file.
The vector is not the pixel intensity matrix, but exactly the binary data of file. So I need to fwrite the vector into a temp jpg file to hard disk, then imread that file as matrix in memory.
Because the number of jpg can be hundreds of thousands, so the frequent io from hard disc make the process very slow.
Is there a way to "recognize" the uint8 vector as if it is on the hard drive, then read it as a image file into imread?
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 4 日
For jpeg in particular, imread() invokes a function that calls upon a .mex* file to do the reading. It is likely that the file invokes libjpeg .
I believe that there is a route to do what you want by using Java. Java permits defining a Java.io.FileInputStream from memory (Byte array), and ImageIO.read() can be used to read images from FileInputStream .
I do not have any code that puts all this together; I have not used Java much.
  1 件のコメント
raym
raym 2020 年 8 月 6 日
編集済み: raym 2020 年 8 月 6 日
I have used the java way to do the rgb binary reading, and use imwrite to write jpg. the speed increased from 3 round/s to 15 round/s. The SSD is even faster: 18~19 round/s.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 8 月 4 日
Of course imread() will "recognize" the image file on disk as a uint8 jpg image if you got it written out properly. I don't know of anyway to decompress a JPG array that's in binary in memory so writing it out to disk to read back in may be the way you need to do it. If that's too slow, you can use solid state drive instead of a hard drive. Exactly how slow is it? For me, it typically takes less than a second to read in an image from my SSD.
  4 件のコメント
raym
raym 2020 年 8 月 4 日
編集済み: raym 2020 年 8 月 4 日
Yes. It is interesting to know why so many funciton/command/API that receive a filepath input cannot also accept a binary stream of the same binary data in hard disk.
Image Analyst
Image Analyst 2020 年 8 月 4 日
You can put it in as a suggestion but I think it would rarely be used by others so it probably will never rise to the top of the priority list. In over 40 years of image processing I've never had to do that.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by