So I just found out that PIL will load images from a memory buffer... we should have something like this as well...
![](https://secure.gravatar.com/avatar/20ecc2648c30f3c3c5a37804709da79f.jpg?s=120&d=mm&r=g)
I was trying to figure out last night how to get libjpeg to decode a jpeg which existed in memory, and write the decoded image to a memory buffer. I failed. The use case is this: I connect to a wireless video camera and make requests for image via HTTP GET. The image is sent in jpeg format as a stream of bytes which gets stored in a python buffer object. I need to convert this jpeg to an RGB numpy array. This turned out to be trivial to do with PIL and its file parser that accepts a stream of bytes. in essence: In [1]: import httplib In [2]: from PIL import ImageFile In [3]: import numpy as np In [4]: conn = httplib.HTTPConnection('www.therealstevencolbert.com') In [5]: conn.request('GET', '/dump/IMG_0408_rs.JPG') In [6]: r1 = conn.getresponse() In [7]: r1.status Out[7]: 200 In [8]: data = r1.read() In [9]: parser = ImageFile.Parser() In [10]: parser.feed(data) In [11]: img = parser.close() In [12]: img.show() In [13]: numpyimg = np.asarray(img) In [14]: numpyimg.shape Out[14]: (768, 1024, 3) In [15]: numpyimg.dtype Out[15]: dtype('uint8') This is incredibly valuable and I think we should consider adding such capability to scikits image. I'd even be willing to work on this after I'm done with the opencv stuff. Cheers! Chris
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
Hi Chris 2009/10/13 Chris Colbert <sccolbert@gmail.com>:
This is incredibly valuable and I think we should consider adding such capability to scikits image. I'd even be willing to work on this after I'm done with the opencv stuff.
We may be able to modify imread in a trivial way to handle this. See http://projects.scipy.org/numpy/browser/trunk/numpy/lib/_datasource.py Stéfan
participants (2)
-
Chris Colbert
-
Stéfan van der Walt