9

i am trying to get to load 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 get to see the image matrix?

Constantinius
  • 32,691
  • 7
  • 72
  • 83
Rory Lester
  • 2,638
  • 11
  • 47
  • 65

3 Answers3

15

You can use numpy.asarray():

>>> import Image, numpy
>>> numpy.asarray(Image.open('1.jpg').convert('L'))
Blender
  • 275,078
  • 51
  • 420
  • 480
5

Function load will give you access to pixels like this:

b = im.load()
print b[x,y]
b[x,y] = 128    # or a tupple if you use another color mode
MatthieuW
  • 2,222
  • 14
  • 25
2

im.show() will display it in a pop-up window.

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

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

mhawke
  • 80,261
  • 9
  • 108
  • 134