Which conversion formula does matlab use for rgb2ycbcr?

12 次查看(过去 30 天)
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?

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by