[Image-SIG] Re: help converting images

Fredrik Lundh fredrik@pythonware.com
Thu, 15 May 2003 20:38:32 +0200


Vein Kong wrote:

> I'm trying to convert a "L" image to an "RGB" image.  How would I set
> the intensity of each color channel? I just want to convert the "L"
> image to say all blue.  How would I go about doing this?

the default conversion simply copies the "L" value to all three color
bands (this is the usual way to do this, and is reversible)

if you want to apply different transfer functions, process each band
separately, and use the merge function to combine them:

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

bands = (
    im,
    Image.new("L", im.size), # black band
    Image.new("L", im.size), # black band
)

rgb = Image.merge("RGB", bands)


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
)

</F>