average of PIL images

Larry Bates larry.bates at websafe.com
Mon Feb 18 15:50:16 EST 2008


vaneric wrote:
> hi
> i have a set of RGB images of diff faces (of people )as a 2 dim
> numpyarray
> ..something like
> threefaces=array([[xa1,xa2,xa3],
>        [xb1,xb2,xb3],
>        [xc1,xc2,xc3]])
> where xa1,xa2,xa3 are  tuples each representing rgb values of a pixel
> of first image ..
> 
> i need to create the average face image and display it.problem is i
> need to calculate (xa1+xb1+xc1)/3  etc to calculate avearge value of
> each pixel.how can i do this calculation.do i need to convert the
> r,g,b in to a single value for each pixel? the average value of a
> pixel will be a float isn't it? how can i create a PIL image from
> this?
> any help,directive greatly appreciated
> eric

Take a look at ImageChops.difference.  I've used it to calculate a
difference value as follows:

diff=ImageChops.difference(im1, im2)
totaldiff=sum(ImageStat.Stat(diff)._getmedian())

Maybe at least this will point you in the right direction.

-Larry Bates



More information about the Python-list mailing list