Ask Your Question
0

calculate the YUV of a pixel without color space transformation

asked Mar 8 '15

begueradj gravatar image

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 ?

Preview: (hide)

Comments

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

theodore gravatar imagetheodore (Mar 8 '15)edit

1 answer

Sort by » oldest newest most voted
3

answered Mar 8 '15

theodore gravatar image

updated Mar 8 '15

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;
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 8 '15

Seen: 472 times

Last updated: Mar 08 '15