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?
<PIL.Image.Image image mode=L size=92x112 at 0x2F905F8>
You can use numpy.asarray() :
numpy.asarray()
>>> import Image, numpy >>> numpy.asarray(Image.open('1.jpg').convert('L'))
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
im.show() display it in a popup window.
im.show()
im.tostring() will unload the image as a byte string.
im.tostring()
im.save() to save it to a file.
im.save()