PEP368 and pixeliterators

Rhodri James rhodri at
Sun Jul 5 18:03:13 EDT 2009

On Fri, 03 Jul 2009 09:21:09 +0100, Steven D'Aprano  
<steve at> wrote:

> On Thu, 02 Jul 2009 10:32:04 +0200, Joachim Strömbergson wrote:
>> for pixel in rgb_image:
>>     # swap red and blue, and set green to 0 pixel.value = pixel.b, 0,
>>     pixel.r
>> The idea I'm having is that fundamentally the image is made up of a 2D
>> array of pixels, not rows of pixels.
> A 2D array implies rows (and columns) of pixels.

But not necessarily an internal representation in which those rows or
columns are contiguous.  An efficient internal storage format might
well include margins to make transform edge cases easier, or store
the pixel components in separate arrays, or both.  I'd imagine that
quite frequently, the iterator across all pixels will in fact just
be hiding from the programmer the fact that it's really iterating
by row and then by pixel.  At Python's level of abstraction, that's
just fine, but the assumption that an image is made up of a 2D
array of pixels is not safe.

Rhodri James *-* Wildebeest Herder to the Masses

More information about the Python-list mailing list