Sunday, October 18, 2015

Read Pixel Value of Image using Python and PIL Module

 Open the Image to im using Image.open() syntax

 Load the value of im into a and now we have 2D tuple and live become easier, :)

.
from __future__ import  print_function
from PIL import  Image

im = Image.open("gb/lena.jpg")
a = im.load()

print('a[0,0]    = ',a[0,0])
print('a[0,0][0] = ',a[0,0][0])
print('a[0,0][1] = ',a[0,0][1])
print('a[0,0][2] = ',a[0,0][2])

If we run it


Nugrohos-MacBook-Air:citra nugroho$ python readIm.py 
a[0,0]    =  (226, 161, 119)
a[0,0][0] =  226
a[0,0][1] =  161
a[0,0][2] =  119
  .