how can I convert an image into a matrix?
akhar
akhar at videotron.ca
Sun May 27 00:43:01 EDT 2001
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
More information about the Python-list
mailing list