First time here? Check out the FAQ!

Ask Your Question
0

RGB to YUV color space conversion for a image

asked Feb 26 '14

Sajal Gupta gravatar image

Can anybody help me out with the complete method/code/inbuilt library function for converting an rgb mat image to an yuv color space.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Feb 26 '14

updated Feb 26 '14

It is very simple, you just have to know that YUV is as good as the same as YCrCb color space, the second one is for digital tv compared to YUV being for analogue tv signals, but the results are quite similar.

Mat original_image = imread("path_to_image");
Mat converted_image = original.clone();
cvtColor(original_image, converted_image, CV_BGR2YCrCb);

Do mind that openCV doesn't read images in RGB order but in BGR order!

Preview: (hide)

Comments

Isn't it true that the BGR image is 3 channel, 24 bits per pixel and padded with additional 8 bits to make it 32-bits per pixel? How is the YCrCb image representation done? It would be 3 channel (2 for Y, 1 for Cr and 1 for Cb), but would it be 24-bits per pixel or 32-bits per pixel? What exact member variable of converted_image matrix be different from original_image matrix?

Srujan gravatar imageSrujan (Sep 13 '16)edit

Question Tools

Stats

Asked: Feb 26 '14

Seen: 14,925 times

Last updated: Feb 26 '14