[Image-SIG] Re: help converting images

Fredrik Lundh fredrik@pythonware.com
Fri, 16 May 2003 15:10:58 +0200


I wrote:

> you can also use point to process each band individually:
>
> bands = (
>     im.point(lambda x: x*0.3), # 30% to red
>     im.point(lambda x: x*0.6), # 60% to green
>     im.point(lambda x: x*0.2), # 20% to blue
> )

another way to do this is to prepare a lookup table, and
use the "putpalette" method to convert the "L" image into
a "P" image, before converting it to RGB:

im = Image.open("some monochrome image")

# built a palette [red0, green0, blue0, red1, green1, blue1, ...]
lut = []
for i in range(256):
    lut.extend((i*0.5, i*0.6, i*0.1))

im.putpalette(lut)

im = im.convert("RGB")

</F>