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

Ray Pasco pascor at hotpop.com
Thu Mar 10 17:53:10 CET 2005



-------- Original Message --------
Subject: 	Re: [Image-SIG] RGB conversion to CMKY gives strange results
Date: 	Thu, 10 Mar 2005 10:37:22 -0500
From: 	Ray Pasco <pascor at hotpop.com>
To: 	Jeff Epler <jepler at unpythonic.net>
References: 	<422FCD77.7000306 at hotpop.com> 
<20050310131618.GC6694 at unpythonic.net>



Jeff - Thanks for the explainations.  My goal is to manipulate only the 
brightness or luminosity
as effeciently as possible. I'm not very familiar with non-RGB 
colorspaces, but I can find out.
Since conversions to HSV and HSL do not exist in PIL, I was hoping to 
manipulate the K values
in the CMYK colorspace and then convert back to RGB.  I know know that 
this is not
possible since this conversion is not done correctly. I could convert to 
another colorspace
using numeric or numarray, but this would be slow.

How can the im.point() function be used for an algorithm that requires 
"If" statements ?
The "im.point (table)" variation is undocumented and the "im.point 
(function) image"
is variation is limited to producing only binary mode "1" images. What 
is that token "image"
doing at the end there ?  Not only that, but the existing documentation 
must be wrong, since
both variations call for a "mode" parameter that is not used at all in 
the documentation's own example !

Do you know what's really going on ?

Thanks,
Ray Pasco


Jeff Epler wrote:

>The algorithm that im.convert("CMYK") uses is this: (C code)
>    static void
>    rgb2cmyk(UINT8* out, const UINT8* in, int xsize)
>    {
>        int x;
>        for (x = 0; x < xsize; x++) {
>            /* Note: no undercolour removal */
>            *out++ = ~(*in++);
>            *out++ = ~(*in++);
>            *out++ = ~(*in++);
>            *out++ = 0; in++;
>        }
>    }
>All numbers are in the inclusive range [0, 255] in this case.  If "in"
>was 0, then out is 255, so it's like the algorithm on the page you
>mentouned for RGB->CMY, where the value 255 corresponds to 1.0, and K is
>simply set to 0 all the time.
>
>Using numeric or numarray, it is probably possible to do the CMY->CMYK
>conversion step described on the page you mentioned, and have the
>resulting code run fairly quickly.
>
>As for conversions from RGB to other 3-component color systems, you can
>use the "im.convert(mode, matrix)" function with the right matrix.  An
>example is in the documentation for converting to the XYZ colorspace.
>
>This block of code, common to many of the conversion functions on that
>web page you mentioned, has to do with doing gamma conversion:
>    if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055
>    else                     var_R = 12.92 * var_R
>    if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055
>    else                     var_G = 12.92 * var_G
>    if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055
>    else                     var_B = 12.92 * var_B
>To perform this step in PIL, you would use the im.point method with a
>properly initialized table.
>
>Jeff
>  
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20050310/3d71300b/attachment-0001.htm


More information about the Image-SIG mailing list