Fastest Way To Loop Through Every Pixel

Fredrik Lundh fredrik at pythonware.com
Mon Jul 31 10:57:08 EDT 2006


Chaos wrote:

> I have tried PIL. Not only that, but the Image.eval function had no
> success either. I did some tests and I found out that Image.eval only
> called the function a certain number of times either 250, or 255.
> Unless I can find a working example for this function, its impossible
> to use.

you might have better success by asking questions about the problem 
you're trying to solve, rather than about some artifact of your first 
attempt to solve it...

the following PIL snippet locates the darkest pixel in an image in about 
0.5 milliseconds for a 200x200 RGB image, on my machine:

     im = im.convert("L") # convert to grayscale
     lo, hi = im.getextrema() # find darkest pixel value
     lo = im.point(lambda x: x == lo) # highlight darkest pixel value
     x, y, _, _ = lo.getbbox() # locate uppermost/leftmost dark pixel

</F>




More information about the Python-list mailing list