# calculate the YUV of a pixel without color space transformation

I load a picture in its BGR color space.

Is it possible todisplay the YUV values of a given pixel without transforming the color space from BGR to YUV ?

edit retag close merge delete

did you see my comment in your previous question? Moreover, how do you expect to obtain the YUV values without applying the appropriate transformation?

( 2015-03-08 17:32:33 -0500 )edit

Sort by ยป oldest newest most voted

You need to apply the following transformations:

Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16

Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128

//Read in an image in BGR
Mat src = imread("bgr.png");

//If (x,y) are the coordinates of the pixel that you want to transform then
uchar Y = (0.257 * src.at<Vec3b>(x, y)[2]) + (0.504 * src.at<Vec3b>(x, y)[1]) + (0.098 * src.at<Vec3b>(x, y)[0]) + 16;
uchar U = -(0.148 * src.at<Vec3b>(x, y)[2]) - (0.291 * src.at<Vec3b>(x, y)[1]) + (0.439 * src.at<Vec3b>(x, y)[0]) + 128;
uchar V = (0.439 * src.at<Vec3b>(x, y)[2]) - (0.368 * src.at<Vec3b>(x, y)[1]) - (0.071 *  src.at<Vec3b>(x, y)[0]) + 128;

more

## Stats

Asked: 2015-03-08 16:33:11 -0500

Seen: 189 times

Last updated: Mar 08 '15