average of PIL images

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Feb 19 05:47:05 EST 2008


On 19 feb, 06:28, vaneric <vaneric... at gmail.com> wrote:
> > > def rgbTopixelvalue((r,g,b)):
> > >    alpha=255
> > >    return unpack("l", pack("BBBB", b, g, r, alpha))[0]
>
> > That's much worse than averaging the R,G,B components.
>
> oops!
> the intention was to pack r,g,b components into a single value sothat
> calculations like finding covariant matrix of a set of images etc can
> be done..(i need to represent each image as an array of  values(either
> long or float)..i can't work with an array of tuples of ints..
>
> > As said above, try to compute using another color space, try HSL. The
> > colorsys module can transform from/to RGB.
>
> even if i convert from rgb to hsl i will have a tuple(h,s,l) for each
> pixel and again i will have to convert it into a single value which i
> can use in matrix multipln etc
>
> is there a workaround sothat rgb color images can be worked on? any
> advice most welcome..

a) Work with the 3 components in parallel (that is, use 3 separate
matrices, one for each component, and regenerate the image at the
end).

b) Convert to grayscale (and lose the color information)

--
Gabriel Genellina



More information about the Python-list mailing list