Python gets a PIL image matrix

I am trying to upload an image, convert it and print the matrix. I have the following code;

im = Image.open("1.jpg") im = im.convert("L") print im 

when I print 'im', I get this <PIL.Image.Image image mode=L size=92x112 at 0x2F905F8> . How can I see the image matrix?

+7
source share
3 answers

You can use numpy.asarray() :

 >>> import Image, numpy >>> numpy.asarray(Image.open('1.jpg').convert('L')) 
+11
source

Functional load will give you access to pixels as follows:

 b = im.load() print b[x,y] b[x,y] = 128 # or a tupple if you use another color mode 
+5
source

im.show() display it in a popup window.

im.tostring() will unload the image as a byte string.

im.save() to save it to a file.

+1
source

All Articles