tags:

views:

446

answers:

2

The formula says:

Y = 0.299 * R + 0.587 * G + 0.114 * B;

U = -0.14713 * R - 0.28886 * G + 0.436 * B;

V = 0.615 * R - 0.51499 * G - 0.10001 * B;

What if, for example, the U variable becomes negative?

U = -0.14713 * R - 0.28886 * G + 0.436 * B;

Assume maximum values for R and G (ones) and B = 0 So, I am interested in implementing this convetion function in OpenCV, So, how to deal with negative values? Using float image? anyway please explain me, may be I don't understand something..

+3  A: 

Y, U and V are all allowed to be negative when represented by decimals, according to the YUV color plane.

YUV Color space

Dolph
+2  A: 

You can convert RGB<->YUV in OpenCV with cvtColor using the code CV_YCrCb2RGB for YUV->RGB and CV_RGBYCrCb for RGB->YUV.

void cvCvtColor(const CvArr* src, CvArr* dst, int code)

Converts an image from one color space to another.

Jacob
Thank you!! I searched for such a function and I thought that YCrCb is something different than YUV...
maximus
No problem. Note that you can convert 3-channel images as well. If you need to merge the Y,U and Vcomponents, you can do that with `merge` which takes a `vector<Mat>` object.
Jacob