[Tutor] im.getdata()

Alan Gauld alan.gauld at btinternet.com
Sun Jul 1 19:15:23 CEST 2007


"elis aeris" <hunter92383 at gmail.com> wrote

> *im.getdata()* => sequence
>
> Returns the contents of an image as a sequence object
> ...
> Note that the sequence object returned by this method is an internal 
> PIL
> data type, which only supports certain sequence operations, 
> including
> iteration and basic sequence access.

> How do I find out how the list look like?
>
> Is it list[x][y]  ?
> or rather, how did you find out how this internal data type look 
> like?

I'm not sure why you care what it looks like internally, you can use
indexing to access the pixels and you can iterate over them.
What more do you need? The indexing will be one dimensional
since the help page told you that the data was flattened. Thus

123
456
789

becomes

123456789

But mostly you won't care because you can iterate over the list
using a standard for loop.

And as ever in Python the easiest way to find out how things work
is just to try it in the interpreter. Use a small bitmap (16x16 say?)
and load it into a PIL image, use getdata and see what it looks like
when you index it, iterate over it and print it. Working with the
interpreter can eliminate most uncertainties when working with Python.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list