[Tutor] im.getdata()

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sun Jul 1 21:02:10 CEST 2007

elis aeris schreef:
> Googling "PIL Handbook" yields this page
> http://www.pythonware.com/library/pil/handbook/image.htm 
> <http://www.pythonware.com/library/pil/handbook/image.htm>
> and, as I said,
> """
>      getdata
> *im.getdata()* => sequence

If you're using PIL >= 1.1.6, there's also a pixel access object you can 
use (the documentation is on that same page, in the 'load' section:

"(New in 1.1.6) In 1.1.6 and later, load returns a pixel access object 
that can be used to read and modify pixels. The access object behaves 
like a 2-dimensional array, so you can do:

pix = im.load()
print pix[x, y]
pix[x, y] = value

Access via this object is a lot faster than getpixel and putpixel."

Perhaps that's more useful to you?

A lot depends on exactly what you want to do with the pixel values. I 
think you would do everyone (including yourself) a favor by just telling 
us what you're going to do with the pixel values.

If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

More information about the Tutor mailing list