# 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?

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

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

more

Official site

GitHub

Wiki

Documentation