Fastest Way To Loop Through Every Pixel

Chaos psnim2000 at gmail.com
Sun Jul 30 13:28:43 EDT 2006


Paul McGuire wrote:
> "Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote in message
> news:Grhyg.21879$Cn6.17684 at tornado.texas.rr.com...
> > "Chaos" <psnim2000 at gmail.com> wrote in message
> > news:1154055002.495073.171650 at i3g2000cwc.googlegroups.com...
> > >
> > >
> > > myCol = (0.3 * image.GetRed(thisX, thisY)) + (0.59 *
> > > image.GetGreen(thisX, thisY)) + (0.11 * image.GetBlue(thisX, thisY))
> > > if myCol < darkestCol:
> > >    darkestCol = myCol
> > >    possX = thisX
> > >    possY = thisY
> > >
> >
> > Psyco may be of some help to you, especially if you extract out your myCol
> > expression into its own function, something like:
> >
> > def darkness(img,x,y):
> >     return  (0.3 * img.GetRed(x,y)) + (0.59 * img.GetGreen(x,y)) + (0.11 *
> > img.GetBlue(x,y))
> >
> <snip>
>
> Even better than my other suggestions might be to write this function, and
> then wrap it in a memoizing decorator
> (http://wiki.python.org/moin/PythonDecoratorLibrary#head-11870a08b0fa59a8622
> 201abfac735ea47ffade5) - surely there must be some repeated colors in your
> image.
>
> -- Paul

Its not only finding the darkest color, but also finding the X position
and Y Position of the darkest color.




More information about the Python-list mailing list