Ask Your Question
0

calculate the YUV of a pixel without color space transformation

asked 2015-03-08 16:33:11 -0600

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 ?

edit retag flag offensive close merge delete

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 ( 2015-03-08 17:32:33 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-03-08 17:18:44 -0600

theodore gravatar image

updated 2015-03-08 17:19:17 -0600

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;
edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 461 times

Last updated: Mar 08 '15