average of PIL images

vaneric vaneric001 at gmail.com
Tue Feb 19 06:03:31 CET 2008

On Feb 19, 1:38 am, Robert Kern <robert.k... at gmail.com> wrote:
>Averaging color
> images is tricky; you really shouldn't do it in the RGB colorspace.
thanx for the guidance and detailed replies..I  tried  to pack the
r,g,b into a single value like below(something a member posted in the

def rgbTopixelvalue((r,g,b)):
   return unpack("l", pack("BBBB", b, g, r, alpha))[0]

if i apply this for all images i can represent each image as an array
of longs instead of tuples.then for a pixel i can calculate the
average value
after this if i do the casting as you advised and create the avg
 avgface = avgface.astype(numpy.uint8)
 img = Image.fromstring('L', (width, height), avgface.tostring())

is there something wrong with my approach? I am a newbie in PIL/
imageprocessing ..so i would greately appreciate feedback

More information about the Python-list mailing list