average of PIL images

vaneric vaneric001 at gmail.com
Tue Feb 19 01:01:04 EST 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.

hi,
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
past)

def rgbTopixelvalue((r,g,b)):
   alpha=255
   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
image
 avgface = avgface.astype(numpy.uint8)

here if i use these pixelvalues to create an imag
 img =Image.fromstring('RGB', (width, height), avgface.tostring())
it will fail because of -'not enough image data'..is there an
alternative to create average rgb color image ?(i want to keep the rgb
so can't convert to greyscale)

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



More information about the Python-list mailing list