average of PIL images
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Feb 19 02:13:02 EST 2008
En Tue, 19 Feb 2008 04:01:04 -0200, vaneric <vaneric001 at gmail.com>
escribió:
> 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]
That's much worse than averaging the R,G,B components. First, you have to
omit the alfa value (or set it at the end). Then, consider this example:
(0,0,0)=black and (0,1,0)=almost black, average = (0,0,128) = dark blue, a
total nonsense.
As said above, try to compute using another color space, try HSL. The
colorsys module can transform from/to RGB.
--
Gabriel Genellina
More information about the Python-list
mailing list