Hello Everyone,
I have a string which contains image data in jpeg encoded format.
gm.Image():fromString() function expects normal string, so when I provided jpeg encoded string it is giving empty image (i.e., image size of 0)
im= gm.Image()
im:fromString(data) -- data contains jpeg encoded string
print(#im) -- displays 0
image:load() expects a filename. So, probably we may have to write the jpeg encoded string data into temporary file and this file has to be provided as input to the image:load(). But this step effects run time performance a lot. I have around 50 K images.
In caffe there is image.open() function and StringIO. So, using the below code it is possible to convert the string to image
>>>from StringIO import StringIO
>>>from PIL import Image
>>>image_file = StringIO(open("test.jpg",'rb').read())
>>>im = Image.open(image_file)
>>>print im.size, im.mode
(2121, 3508) RGB
stringio is also present in Lua Penlight, but the problem is in Torch there is no image:open() function, thus there is no way to provide already opened image file handler as input to image routines, all the existing image routines expects filename as parameter.
Could someone please let me know if there is any other way. Thanks for your time and help.
-
Regards,
Sravan