YUV To RGB
This algorithm converts YUV color space to RGB color model.
class RGB
{
public:
unsigned char R;
unsigned char G;
unsigned char B;
RGB(unsigned char r, unsigned char g, unsigned char b)
{
R = r;
G = g;
B = b;
}
bool Equals(RGB rgb)
{
return (R == rgb.R) && (G == rgb.G) && (B == rgb.B);
}
};
class YUV
{
public:
double Y;
double U;
double V;
YUV(double y, double u, double v)
{
Y = y;
U = u;
V = v;
}
bool Equals(YUV yuv)
{
return (Y == yuv.Y) && (U == yuv.U) && (V == yuv.V);
}
};
static RGB YUVToRGB(YUV yuv) {
unsigned char r = (unsigned char)(yuv.Y + 1.4075 * (yuv.V - 128));
unsigned char g = (unsigned char)(yuv.Y - 0.3455 * (yuv.U - 128) - (0.7169 * (yuv.V - 128)));
unsigned char b = (unsigned char)(yuv.Y + 1.7790 * (yuv.U - 128));
return RGB(r, g, b);
}
Example
YUV data = YUV(82, 140, 87);
RGB value = YUVToRGB(data);
Output
R: 24
G: 107
B: 103