Azzera filtri
Azzera filtri

Which conversion formula does matlab use for rgb2ycbcr?

17 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 13 Feb 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 Commento
Mohana Singh
Mohana Singh il 13 Feb 2021
Just found out that 'rgb2gray' infact uses the `0.299*r+0.587*g+0.114*b` formula as per the source code.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by