Thursday, December 22, 2011

CMY(K) color image

CMY (or its variant CMYK) color space uses as primary colors: cyan, magenta, and yellow.
This color space used by printers is interesting because, this is an example of a subtractive color model. When you add color(s), you converge towards black color.
1- CMY color space
In this color space, (0,0,0)CMY is white and (255,255,255)CMY is black. As shown in Fig.1,  the primary colors cyan, magenta, and yellow have respectively the values (255,0,0)CMY, (0,255,0)CMY, and  (0,0,255)CMY. For example, green is equal to (255,0,255)CMY corresponding to the complementary color in RGB (0,255,0)RGB.

Fig.1: Cyan, magenta, and yellow: the three primary colors in this subtractive color space.
In ImageJ, the creation of the CMY color model of Fig.1 is done by using the script of RGB color space that I previously described [see post] and by inverting the resulting (RGB) image (Edit > Invert).

2- How can we convert a RGB image to a CMY ?
Fig. 2: Test RGB image from File > Open Samples > Clown (14K).
As you've seen before, the CMY image is the complementary of the RGB one. Thus, a simple inversion of the RGB image followed by a Image > Color > Split Channels yields the three CMY channels as shown in Fig. 3 from the clown RGB image.
Fig. 3: Steps to get the three cyan, magenta, and yellow channels from the RGB image of Fig. 2. A) Inverted RGB image. B-D) Cyan, magenta, and yellow channels.
Keep in mind that CMY is a subtractive color space and thus, a maximum of cyan, magenta, and yellow corresponds to black color like in the bottom left corner of the clown image of Fig.3B-D whereas the top of the red nose is dark (no color ink is needed) in the three channels corresponding to white.

Now, to see these channels with their shades of cyan, magenta, and yellow, we have to convert again these channels into RGB (Fig.4).

Fig.4: Clown in CMY color space. Each channel is represented in shades.
3- CMY+K color model
In an ink jet printer, there are four inks: the three primary colors plus the black color. This is why we speak about CMYK color model. The 'K' means Key ( not blacK) and this terminology is explained in Wikipedia [Link].
Why a fourth black color ?
Technically, the mixture of the three color inks didn't give a pure black and moreover, they  are expensive. Thus, the black ink is used to solve these disadvantages.
There are various algorithms to compute the fourth channel as described in Wikipedia [Link].In my case, I use the most common ...
  • First, invert the RGB image and split the channels as detailed above.
  • Second, calculate the K channel by computing the min(cyan, magenta, yellow).
  • Third, subtract the K channel to the three primary C,M,and Y channels.
Et voilà!

If you compare the channels of Fig. 3 with those of Fig. 5, the main difference appears with the cyan channel which is completely black.
Fig. 5: Cyan, magenta, yellow, and key channels
The IJ script is the following

+++ IJ snippet +++ +++ End of IJ snippet +++

Now, in color, you get ...

Fig.6: Clown in CMYK color model. The cyan channel is now empty.
4- Links

1 comment:

  1. CMYK CMY Converter, is a fast app to convert units of color: CMY to CMYK, very useful for graphic designers and web designers