views:

61

answers:

4

Hi, I want to do some image processing using Python - is there a simple way to import .png image files as a matrix of greyscale/RGB values (possibly using PIL)?

+2  A: 

im.load in PIL returns a matrix-like object.

katrielalex
Thanks - but I couldn't figure out which attribute to access from the return value of im.load()...
Stephen
Seems you didn't read PIL manual, there is a simple case =>pix = im.load()print pix[x, y]What's unclear here ?
0x69
A: 

Yes. Use PIL.

Do you have a more specific question? Perhaps some code you tried?

S.Lott
+2  A: 

you can use PyGame image and use PixelArray to access the pixeldata

Nikolaus Gradwohl
thanks - i will have to look into that. for now, i happened to have scipy and PIL installed already...
Stephen
+2  A: 

scipy.misc.imread() will return a Numpy array, which is handy for lots of things.

ptomato
fantastic. worked like a charm.
Stephen
matplotlib.imread reads .png s (only) even without PIL installed.
Denis