l'image de fond

fr       en

Color Processing

Color Space for Printing

CMY

The color used in print is substractive. It uses the threeprimarycolors cyan (C), magenta (M) et yellow (Y). The sheet on wich we print are white so if C = M = Y = 0 no ink is used, so we have white. On the other hand, if C = M = Y = 1 The three inks are used and satured so the final color will be black. A simple way to compute the three components is:

C = 1 - R ,
M = 1 - G ,
Y = 1 - B ,

Matlab program:

C=(255-R);
M=(255-G);
Y=(255-B);

figure(  'Name','RGB --> CMY',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(321)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(323)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(325)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(322)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(324)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(326)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
 

and an example
rgbcmy

CMYK method 1

The saturation of the three components CMY doesn't make black for real, to correct it we generaly use black ink in addition. A simple technic is to compute the black component in that way:

K = min ( C , M , Y )

We compute the new components CMY thanks to K.

( C ' M ' Y ' K ' ) = ( C - K M - K Y - K K )

we can use the next program:

% conversion RGB --> CMYK
% methode 1
C=(255-R);
M=(255-G);
Y=(255-B);
K=min(cat(3,C,M,Y),[],3);
C=C-K;
M=M-K;
Y=Y-K;

figure(  'Name','RGB --> CMYK Methode 1',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')
 

An example
rgbcmyk1

CMYK method 2

An other method is to reduce the components CMY by a factor f where: f = 1 1 - K if K < 1 and 1 if K = 1 . So we have

( C ' M ' Y ' K ' ) = ( ( C - K M - K Y - K ) f K )

In this way if R = G = B then the print just use black ink.
here, the program:

% conversion RGB --> CMYK
% methode 2
% normalisation
Rn=R/255;
Gn=G/255;
Bn=B/255;
Cn=(1-Rn);
Mn=(1-Gn);
Yn=(1-Bn);
Kn=min(cat(3,Cn,Mn,Yn),[],3);
Knp=Kn;
Kn=1./(1-Kn);
Kn(Kn==Inf)= 1;
Cn=(Cn-Knp).*Kn;
Mn=(Mn-Knp).*Kn;
Yn=(Yn-Knp).*Kn;
% dénormalisation
C=Cn*255;
M=Mn*255;
Y=Yn*255;
K=Knp*255;
figure(  'Name','RGB --> CMYK Methode 2',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')
 

And an example
rgbcmyk2

CMYK method 3

( C ' M ' Y ' K ' ) = ( C - F U C R ( K ) M - F U C R ( K ) Y - F U C R ( K ) F B G ( K ) )

With

F U C R ( K ) = S k K ,
F B G ( K ) = { 0 f o r K < K o K max K - K o 1 - K o f o r K K o )

The program

% conversion RGB --> CMYK
% methode 3
% normalisation
Rn=R/255;
Gn=G/255;
Bn=B/255;
Cn=(1-Rn);
Mn=(1-Gn);
Yn=(1-Bn);
Kn=min(cat(3,Cn,Mn,Yn),[],3);

Sk = 0.1;
FucrK = Sk * Kn;

Ko = 0.3;
FBGK=(Kn<Ko)* (max(max(Kn))) .* (Kn-Ko)./(1-Ko);
   
Cn=(Cn-FucrK);
Mn=(Mn-FucrK);
Yn=(Yn-FucrK);
Kn=FBGK;
% dénormalisation
C=Cn*255;
M=Mn*255;
Y=Yn*255;
K=Knp*255;
figure(  'Name','RGB --> CMYK Methode 3',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')

An example
rgbcmyk3

Complete Program

clear all;
close all;

[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
          '*.*','All Files' },'mytitle',...
          'C:\Work\myfile.jpg');

img = imread(filename);
[ligne colonne dimension]=size(img);
img=double(img);
R=img(:,:,1);
G=img(:,:,2);
B=img(:,:,3);
Imax = max(max(img));

% conversion RGB --> CMY
C=(255-R);
M=(255-G);
Y=(255-B);

figure(  'Name','RGB --> CMY',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(321)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(323)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(325)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(322)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(324)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(326)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')


% conversion RGB --> CMYK
% methode 1
C=(255-R);
M=(255-G);
Y=(255-B);
K=min(cat(3,C,M,Y),[],3);
C=C-K;
M=M-K;
Y=Y-K;

figure(  'Name','RGB --> CMYK Methode 1',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')

% conversion RGB --> CMYK
% methode 2
% normalisation
Rn=R/255;
Gn=G/255;
Bn=B/255;
Cn=(1-Rn);
Mn=(1-Gn);
Yn=(1-Bn);
Kn=min(cat(3,Cn,Mn,Yn),[],3);
Knp=Kn;
Kn=1./(1-Kn);
Kn(Kn==Inf)= 1;
Cn=(Cn-Knp).*Kn;
Mn=(Mn-Knp).*Kn;
Yn=(Yn-Knp).*Kn;
% dénormalisation
C=Cn*255;
M=Mn*255;
Y=Yn*255;
K=Knp*255;
figure(  'Name','RGB --> CMYK Methode 2',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')


% conversion RGB --> CMYK
% methode 3
% normalisation
Rn=R/255;
Gn=G/255;
Bn=B/255;
Cn=(1-Rn);
Mn=(1-Gn);
Yn=(1-Bn);
Kn=min(cat(3,Cn,Mn,Yn),[],3);

Sk = 0.1;
FucrK = Sk * Kn;

Ko = 0.3;
FBGK=(Kn<Ko)* (max(max(Kn))) .* (Kn-Ko)./(1-Ko);
   
Cn=(Cn-FucrK);
Mn=(Mn-FucrK);
Yn=(Yn-FucrK);
Kn=FBGK;
% dénormalisation
C=Cn*255;
M=Mn*255;
Y=Yn*255;
K=Knp*255;
figure(  'Name','RGB --> CMYK Methode 3',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
vide=zeros(ligne,colonne);
subplot(331)
imshow(uint8(cat(3,R,vide,vide)))
title('Image R origine')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G origine')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image B origine')
 subplot(332)
imshow(uint8(cat(3,vide,C,C)))
title('Image C')
subplot(335)
imshow(uint8(cat(3,M,vide,M)))
title('Image M')
subplot(338)
imshow(uint8(cat(3,Y,Y,vide)))
title('Image Y')
subplot(333)
imshow(uint8(cat(3,K,K,K)))
title('Image K')

Copyright © 2010-2014, all rights reserved, contact: operationpixel@free.fr