Fastest Way To Loop Through Every Pixel

Chaos psnim2000 at gmail.com
Sat Aug 5 19:13:40 EDT 2006


Fredrik Lundh wrote:
> 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>

thank you that worked perfectly.




More information about the Python-list mailing list