Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use scikit-image to read in an image buffer

Tags:

I already have an in-memory file of an image. I would like to use skimage's io.imread (or equivalent) to read in the image. However, skimage.io.imread() take a file not a buffer

example buffer:

 <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 06 05 ... >

skimage.io.imread() just results in a numpy array.

like image 777
benwiz Avatar asked Aug 19 '16 19:08

benwiz


1 Answers

Try converting the buffer into StringIO and then read it using skimage.io.imread()

import cStringIO

img_stringIO = cStringIO.StringIO(buf)
img = skimage.io.imread(img_stringIO)

You can also read it as :

from PIL import Image
img = Image.open(img_stringIO)
like image 175
Abhijay Ghildyal Avatar answered Sep 23 '22 16:09

Abhijay Ghildyal