[Image-SIG] how can I convert an image into a matrix?

akhar akhar@videotron.ca
Sat, 26 May 2001 21:44:29 -0700


how can I convert an image into a matrix with the associated pixel colour
value ? I tried playing around with PIL and Numeric but I don't get anything
but error messages I tried this:

Import Image, ImageChops, Numeric
im = Image.open("c:/testimg.jpg)
def ImageToArray(i):
    a = Numeric.array(i._tostring(), "b")
    a.shape = i.size[1], i.size[0]
    return a
matrix = ImageToArray(im)

		all I get is this:

"Traceback (innermost last):
  File "<interactive input>", line 1, in ?
  File "<interactive input>", line 2, in imgtoarray
AttributeError: 'JpegImageFile' instance has no attribute '_tostring'
>>> "
And while I am at it how do I use PIL to write images from a stream?

Regards

Stephane