11

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
  • 34,183
  • 8
  • 77
  • 85
Rory Lester
  • 2,858
  • 11
  • 49
  • 66

3 Answers3

16

You can use numpy.asarray():

>>> import Image, numpy
>>> numpy.asarray(Image.open('1.jpg').convert('L'))
Blender
  • 289,723
  • 53
  • 439
  • 496
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,292
  • 15
  • 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
  • 84,695
  • 9
  • 117
  • 138