Johannes Loehnert wrote:
> Am Mittwoch, 30. August 2006 19:20 schrieb Ghalib Suleiman:
>
>> I'm somewhat new to both libraries...is there any way to create a 2D
>> array of pixel values from an image object from the Python Image
>> Library? I'd like to do some arithmetic on the values.
>>
>
> Yes.
>
> To transport the data:
>
>>>> import numpy
>>>> image = <some PIL image>
>>>> arr = numpy.fromstring(image.tostring(), dtype=numpy.uint8)
>>>>
>
> (alternately use dtype=numpy.uint32 if you want RGBA packed in one number).
>
> arr will be a 1d array with length (height * width * b(ytes)pp). Use reshape
> to get it into a reasonable form.
>
On a related note, does anyone have a good recipe for converting a PIL
image to a wxPython image? The last time I tried this, the best I could
come up with was:
stream = cStringIO.StringIO()
img.save(stream, "png") # img is PIL Image
stream.seek(0)
image = wx.ImageFromStream(stream) # image is a wxPython Image
-tim
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion