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

6 次查看(过去 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 CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by