average of PIL images
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Feb 19 05:40:23 EST 2008
On 19 feb, 06:55, 7stud <bbxx789_0... at yahoo.com> wrote:
> On Feb 19, 12:13 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
> > En Tue, 19 Feb 2008 04:01:04 -0200, vaneric <vaneric... 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.
>
> > > 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)
>
> How do you arrive at that average?
(0,0,0) -> 0, (0,1,0) -> 256, (0+256)/2=128, 128 -> (0,0,128)
(ignoring alpha, or using alpha=0)
--
Gabriel Genellina
More information about the Python-list
mailing list