l'image de fond

fr       en

Traitements d'Images Couleurs

Espace de Couleur de Télévision

YUV

C'est l'encodage de base de la télévision analogique. Il est utilisé dans le NTSC et le PAL. La luminance Y se calcule comme suit :

Y = 0. 299 R + 0. 587 G + 0. 114 B

Les composants U et V sont les différences pondérées du rouge et bleu par rapport à la luminance.

U = 0. 492 ( B - Y ) et V = 0. 877 ( R - Y )

On peut aussi écrire la conversion RGB vers YUV de La manière suivante :

( Y U V ) = ( 0. 299 0. 587 0. 114 - 0. 147 - 0. 289 0. 436 0. 615 - 0. 515 - 0. 1 ) ( R G B )

La conversion inverse YUV vers RGB se calcule grâce à :

( R G B ) = ( 1 0 1. 14 1 - 0. 395 - 0. 581 1 2. 032 0 ) ( Y U V )

Le programme Matlab :

% conversion RGB --> YUV
%normalisation des couleurs
Y = 0.299*R + 0.587*G + 0.114*B  ;
U = 0.492*(B-Y);
V = 0.877*(R-Y);
Rp= Y + 1.140*V;
Gp= Y - 0.395*U -0.581*V;
Bp= Y + 2.032*U ;
figure(  'Name','RGB --> YUV',...
            '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)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(U,[min(min(U)) max(max(U))])
colormap(gray)
axis image
title('Image U')
subplot(338)
imagesc(V,[min(min(V)) max(max(V))])
colormap(gray)
axis image
title('Image V')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B reconstruit')

Un exemple :
rgbyuv

YIQ

Il s'agit du système original NTSC. La luminance Y est la même que pour le YUV. I représente la phase (Inphase) et Q la quadrature. U et V subissent un effet miroir et une rotation grâce à un angle b. Voici l'équation :

I = - sin ( b ) U + cos ( b ) V

et

Q = cos ( b ) U + sin ( b ) V

l'angle b est égal à 0.576 soit 33°.

On peut également calculer cette conversion avec :

( Y I Q ) = ( 0. 299 0. 587 0. 114 0. 596 - 0. 274 - 0. 322 0. 211 - 0. 523 0. 312 ) ( R G B )

La conversion inverse est faite grâce à :

( R G B ) = ( 1 0. 956 0. 621 1 - 0. 272 - 0. 647 1 - 1. 106 1. 703 ) ( Y I Q )

Le programme Matlab :

Y = 0.299*R + 0.587*G + 0.114*B  ;
U = 0.492*(B-Y);
V = 0.877*(R-Y);
b=0.576;
I = -sin(b)*U + cos(b)*V ;
Q = cos(b)*U + sin(b)*V ;
Rp= Y +  0.956*I +  0.621*Q;
Gp= Y -  0.272 *I - 0.647*Q;
Bp= Y -  1.106*I + 1.703*Q;

figure(  'Name','RGB --> YIQ',...
            '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')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image G')
 subplot(332)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(I,[min(min(I)) max(max(I))])
colormap(gray)
axis image
title('Image I')
subplot(338)
imagesc(Q,[min(min(Q)) max(max(Q))])
colormap(gray)
axis image
title('Image Q')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B  reconstruit')

Un exemple :
rgbyiq

YCbCr

Cet espace de couleur est un standard international du YUV. Il est utilisé dans la télévision numérique et aussi en compression, notamment en JPEG. On a pour la conversion RGB vers YCbCr :

Y = w r R + w g G + w b B
C b = 0. 5 1 - w b ( B - Y )
C r = 0. 5 1 - w r ( R - Y )

où wr = 0.299, wb = 0.114 et Wc = 1 - wb - wr.
La conversion inverse YCbCr vers RGB se fait grâce à :

R = Y + 1 - w r 0. 5 C r
G = Y + w b ( 1 - w b ) C b - w r ( 1 - w r ) C r 0. 5 ( w g )
B = Y + 1 - w b 0. 5 C b

Cette conversion peut aussi se faire avec les matrices suivantes :

( Y C b C r ) = ( 0. 299 0. 587 0. 114 - 0. 169 - 0. 331 0. 5 0. 5 - 0. 419 - 0. 081 ) ( R G B )
( R G B ) = ( 1 0 1. 403 1 - 0. 344 - 0. 714 1 1. 773 0 ) ( Y Cb Cr )

Le programme Matlab :

% conversion RGB --> YCbCr
%normalisation des couleurs
Wr=0.299;Wb=0.114; Wg=1-Wr-Wb;
Y = Wr*R + Wg*G + Wb*B  ;
Cb= ( 0.5 / ( 1-Wb) ) * (B-Y);
Cr= ( 0.5 / ( 1-Wr) ) * (R-Y);
Rp= Y + ((1 - Wr)/0.5)*Cr;
Gp= Y + (Wb*(1-Wb)*Cb - Wr*(1-Wr)*Cr)/(0.5*(1-Wb-Wr));
Bp= Y + ((1 - Wb)/0.5) * Cb;

figure(  'Name','RGB --> YCbCr',...
            '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)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(Cb,[min(min(Cb)) max(max(Cb))])
colormap(gray)
axis image
title('Image Cb')
subplot(338)
imagesc(Cr,[min(min(Cr)) max(max(Cr))])
colormap(gray)
axis image
title('Image Cr')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B  reconstruit')

Un exemple :
rgbycbcr

Programme complet

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 --> YUV
Y = 0.299*R + 0.587*G + 0.114*B  ;
U = 0.492*(B-Y);
V = 0.877*(R-Y);
Rp= Y + 1.140*V;
Gp= Y - 0.395*U -0.581*V;
Bp= Y + 2.032*U ;
figure(  'Name','RGB --> YUV',...
            '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)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(U,[min(min(U)) max(max(U))])
colormap(gray)
axis image
title('Image U')
subplot(338)
imagesc(V,[min(min(V)) max(max(V))])
colormap(gray)
axis image
title('Image V')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B reconstruit')
% conversion RGB --> YIQ
Y = 0.299*R + 0.587*G + 0.114*B  ;
U = 0.492*(B-Y);
V = 0.877*(R-Y);
b=0.576;
I = -sin(b)*U + cos(b)*V ;
Q = cos(b)*U + sin(b)*V ;
Rp= Y +  0.956*I +  0.621*Q;
Gp= Y -  0.272 *I - 0.647*Q;
Bp= Y -  1.106*I + 1.703*Q;

figure(  'Name','RGB --> YIQ',...
            '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')
subplot(334)
imshow(uint8(cat(3,vide,G,vide)))
title('Image G')
subplot(337)
imshow(uint8(cat(3,vide,vide,B)))
title('Image G')
 subplot(332)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(I,[min(min(I)) max(max(I))])
colormap(gray)
axis image
title('Image I')
subplot(338)
imagesc(Q,[min(min(Q)) max(max(Q))])
colormap(gray)
axis image
title('Image Q')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B  reconstruit')

% conversion RGB --> YCbCr
Wr=0.299;Wb=0.114; Wg=1-Wr-Wb;
Y = Wr*R + Wg*G + Wb*B  ;
Cb= ( 0.5 / ( 1-Wb) ) * (B-Y);
Cr= ( 0.5 / ( 1-Wr) ) * (R-Y);
Rp= Y + ((1 - Wr)/0.5)*Cr;
Gp= Y + (Wb*(1-Wb)*Cb - Wr*(1-Wr)*Cr)/(0.5*(1-Wb-Wr));
Bp= Y + ((1 - Wb)/0.5) * Cb;

figure(  'Name','RGB --> YCbCr',...
            '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)
imagesc(Y,[min(min(Y)) max(max(Y))])
colormap(gray)
axis image
title('Image Y')
subplot(335)
imagesc(Cb,[min(min(Cb)) max(max(Cb))])
colormap(gray)
axis image
title('Image Cb')
subplot(338)
imagesc(Cr,[min(min(Cr)) max(max(Cr))])
colormap(gray)
axis image
title('Image Cr')
subplot(333)
imshow(uint8(cat(3,Rp,vide,vide)))
title('Image R reconstruit')
subplot(336)
imshow(uint8(cat(3,vide,Gp,vide)))
title('Image G reconstruit')
subplot(339)
imshow(uint8(cat(3,vide,vide,Bp)))
title('Image B  reconstruit')

Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr