Which conversion formula does matlab use for rgb2ycbcr?
11 views (last 30 days)
Show older comments
Mohana Singh
on 13 Feb 2021
Commented: Mohana Singh
on 13 Feb 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?
0 Comments
Accepted Answer
Walter Roberson
on 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
More Answers (0)
See Also
Categories
Find more on Color in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!