[Tutor] Re: getting pixel colors from a bitmap image - speed

Lee Harr missive@hotmail.com
Tue Dec 17 10:53:10 2002


>I am trying to get the colour of a pixel in a bitmap image. i know i
>could use the PIL, like so:

>import Image
>im = Image.open('input.bmp')
>print 'pixel colour is:', im.getpixel((23,45))

>But the program i have in mind needs to do this many times a second, and
>i thought maybe there is a faster way to do this, esp. as the PIL warns
>about the speed of using this method.

>Does any one know if there is a similar call either in the PIL or in
>another library, which is faster?


I doubt that it is _much_ faster (if at all... I have not done any
benchmarking) but another way to do this would be with pygame and
its surfarray module. surfarray uses Numeric to speed up processing
images at the pixel level.

Probably best to just pick one and try it and see if it is "fast
enough". If not you can then profile and try to get through the
bottleneck.




_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail