[Image-SIG] RGB conversion to CMKY gives strange results

Jeff Epler jepler at unpythonic.net
Thu Mar 10 18:48:48 CET 2005


(Please copy the list with these posts.  Maybe others will benefit from
this discussion someday)

Here's some code that inverts the red channel of an RGB image using
im.point:
    import Image

    inverter = [255-i for i in range(256)]
    unchanged = range(256)
    i = Image.open("input.jpg")
    j = i.point(inverter + unchanged + unchanged)
    j.save("output.jpg")
In this usage, i.point takes a 768-entry list of integers.  The first
256 entries are used to map red values, the second 256 entries to map
green values, and the last 256 entries to map blue values.  You could
change brightness and contrast across all channels by using a ramp
functnction of your choice.  Something like [untested]
    contrast = 1.1  # Increase contrast to 110% of original
    brightness = 16 # Increase brightness by 16/255 ~= 6.25%
    c = [int(min(255, max(0, i * contrast + brightness))) for i in range(255)]
    ...
    j = i.point(c+c+c)

I didn't immediately get the 'im.convert' to XYZ colorspace to work as
documented.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20050310/ea181b23/attachment.pgp


More information about the Image-SIG mailing list