Effacer les filtres
Effacer les filtres

Which conversion formula does matlab use for rgb2ycbcr?

17 vues (au cours des 30 derniers jours)
Mohana Singh
Mohana Singh le 13 Fév 2021
Commenté : Mohana Singh le 13 Fév 2021
In the documentation for rgb2ycbcr, the jpeg recommendation https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf is given as reference. However, i checked the values of luminance channel using rgb2ycbcr as well as directly using the jpeg recommended conversion formula and the luminance channel values are not the same.
i=imread('peppers.png');
YCBCR = rgb2ycbcr(i);
y=YCBCR(:,:,1);
r=i(:,:,1);g=i(:,:,2);b=i(:,:,3);
oury=min(max(0,round(0.299*r+0.587*g+0.114*b)),255);
The values in y and oury differ by ~10. I want to confirm if there's something wrong with my manual approach or matlab uses a slightly different formula?

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Fév 2021
Assuming uint8, the code uses
[0.256788235294118 0.504129411764706 0.0979058823529412
-0.148223529411765 -0.290992156862745 0.43921568627451
0.43921568627451 -0.367788235294118 -0.0714274509803921] * [R;G;B] + [16;128;128]
% This matrix comes from a formula in Poynton's, "Introduction to
% Digital Video" (p. 176, equations 9.6).
See the source code, line 66 or so, matrix origT and divide by the scale factor 255 for uint8
  1 commentaire
Mohana Singh
Mohana Singh le 13 Fév 2021
Just found out that 'rgb2gray' infact uses the `0.299*r+0.587*g+0.114*b` formula as per the source code.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by