benwiz
benwiz

Reputation: 2317

Use scikit-image to read in an image buffer

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.

Upvotes: 6

Views: 5460

Answers (1)

PixelPioneer
PixelPioneer

Reputation: 4170

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)

Upvotes: 3

Related Questions