[Image-SIG] Re: Single pixel paste() speed

Fredrik Lundh fredrik at pythonware.com
Thu Nov 11 17:37:08 CET 2004


Ray Pasco wrote:

> Is there a call that is faster than paste() for replacing a single pixel value ?

putpixel()

populating a python list and using putdata() when you're done can be
faster.

you can also shave off some overhead by "inlining" the low-level
mechanisms used by putpixel:

    im.load()
    putpixel = im.im.putpixel
    for y in ...:
        for x in ...:
            putpixel((x, y), value)

but there's no "fast" way to work with individual pixels in PIL (Python's not fast
enough for this, for most definitions of "fast enough").  if you need to get close to
C speed (or beyond), you need to base your algorithm on operations that process
many pixels at once (convert, point, paste, transform, ImageDraw, etc)

</F> 





More information about the Image-SIG mailing list