[Image-SIG] Help - Palette

Oliver Albrecht 550283447739-0001 at t-online.de
Wed Jun 1 21:02:36 CEST 2005

(I found only the PIL(Draft Edition)(Overview)Books as Docu in the big Web.)

The RGB to P Color-reduction is the best what i've ever seen.
But with a weakness, the BackgroundColor is also reduced(deleted if more 
than 256 colors, i mean)
Now i've try to make a background mask before.
(After convert('P') the Palette has 1 free (unused color)Id for a Mask!?)

>(1.0b1 released)
> + Added Toby J. Sargeant's quantization package.  To enable
>   quantization, use the "palette" option to "convert":
>         imOut = im.convert("P", palette=Image.ADAPTIVE)
>   This can be used with "L", "P", and "RGB" images.  In this
>   version, dithering cannot be used with adaptive palettes.
>   Note: ADAPTIVE currently maps to median cut quantization
>   with 256 colours.  The quantization package also contains
>   a maximum coverage quantizer, which will be supported by
>   future versions of PIL.

This only works with ADAPTIVE=1 , i try it also with a list unsuccessful.
How i can give a referent palette to convert()?

>PIL 1.1.3 Book | March 12, 2002 | Fredrik Lundh, Matthew Ellis
># Note the syntax used to create the mask:
> imout = im.point(lambda i: expression and 255)
> Python only evaluates the portion of a logical expression as is necessary to determine the
> outcome, and returns the last value examined as the result of the expression. So if the
> expression above is false (0), Python does not look at the second operand, and thus
> returns 0. Otherwise, it returns 255.

I want make a Mask from RGB Image from only one color .
I've tryed with point() unsuccessful.
#maskR = source[R].point(lambda i: i == 0 and 255)
#maskG = source[G].point(lambda i: i == 0 and 255)
#maskB = source[B].point(lambda i: i == 132 and 255)
#print mask.getcolors()
#mask = Image.merge(im.mode, (maskR,maskG,maskB))
#mask = mask.convert('1')
#im.paste(colour, None, mask)

Thats my try(has putdata() lesser performance?):
for r, g, b in im.getdata():
     if (r,g,b) != (0,0,132):
     data_list.append((r, g, b))

Is that efficient enough?
I want thanks for every Answers!
I will also support the PIL/answers to my german py forum/wiki


More information about the Image-SIG mailing list