[Tutor] 200 dollar questions!
rabidpoobear at gmail.com
Sun Jul 1 07:35:28 CEST 2007
elis aeris wrote:
> which modules and origin is this function?
You can infer from the fact that your image object already has the pixel
data stored within it that
the getdata would be a method of the object.
In other words,
and, if I recall correctly, when you asked where this function was, I
mentioned that it had an entry in the PIL handbook
right next to the getpixel() entry.
Googling "PIL Handbook" yields this page
and, as I said,
*im.getdata()* => sequence
Returns the contents of an image as a sequence object containing pixel
values. The sequence object is flattened, so that values for line one
follow directly after the values of line zero, and so on.
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. To convert it to an ordinary
sequence (e.g. for printing), use *list(im.getdata())*.
*im.getextrema()* => 2-tuple
Returns a 2-tuple containing the minimum and maximum values of the
image. In the current version of PIL, this is only applicable to
*im.getpixel(xy)* => value or tuple
Returns the pixel at the given position. If the image is a multi-layer
image, this method returns a tuple.
Note that this method is rather slow; if you need to process larger
parts of an image from Python, you can either use pixel access objects
(see *load*), or the *getdata* method.
> is it the fastest way to get it?
It depends how much of the pixel data you're using.
If you're using the whole image, then yes, getdata is probably the
If you're using a portion, depending on the dimensions, it may be faster
to getpixel or it may be faster to crop the image and getdata,
there's no telling. You'd have to test.
IF one way were faster for every case, there'd only be one way to do it.
> I am told to optimize getpixel (x, y) alone, so that's the only thing
> i am trying, it's part of a project that will go live in september, so
> the prof we are under hasn't one anything but some introductory readings.
Then keep working with that.
If you have a specific requirement, and they won't let you change it,
then do what you can.
More information about the Tutor