Converting from YCbCr to RGB

5 views (last 30 days)
Sonny
Sonny on 5 Mar 2015
Answered: Daanish Mohammed on 7 Aug 2020
Hello
I have an image that I want to convert from and to the above mentioned.
The array is 512x512x3 with Y, Cb, Cr seperated.
When i used ycbcr2rgb I get a pink image, this is also the case when I try to convert each channel seperately, by using the conversion equations manually.
Could you perhaps help me explain why this happens, or what I'm doing wrong?
Thanks Sonny
  1 Comment
Sonny
Sonny on 5 Mar 2015
An addition is that the three channels in the output of the supposed RGB image isn't red green or blue, but rather the green is closer to grey in all of it, and the B is closer to white in most of it and the same goes for the R channel.

Sign in to comment.

Answers (1)

Daanish Mohammed
Daanish Mohammed on 7 Aug 2020
I encountered the same error. You should make sure that the original image and the one you obtain after reconstruction are of the same type. For me, the former was of type 'uint8' and the latter 'double'. Here's how I did it:
res_img = uint8(zeros(size(img))); % 'img' is the original image (RGB), 'res_img' is the recovered YCbCr image.
res_img(:,:,1) = uint8(res_img_Y); % the 3 channels (Y, Cb, Cr) were all of type double.
res_img(:,:,2) = uint8(res_img_Cb);
res_img(:,:,3) = uint8(res_img_Cr);
final_res_image = (ycbcr2rgb(res_img)); % Converting from YCbCr space to RGB space.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!