1. for computer system, the YUV and RGB range are [0~255] using 8bit to show.
int clip_int ( int value ) { return (value > 255) ? 255 : (value <0) ? 0 : value; }
RGB to YUV:
int y = clip_int(y);
int u = clip_int(u);
int v = clip_int(v);
using the float , the RGB to YUV convert formula :
iy = (65.738 * r + 129.057*g + 25.064*b) / 256 + 16;
iu = (-37.945*r - 74.494*g + 112.439*b) / 256 + 128;
iv = (112.439*r - 94.154*g - 18.285*b) / 256 + 128;
or
y = (0.2568*r + 0.5041*g + 0.0979*b) + 16;
u = (-0.1482*r - 0.2910*g + 0.4392*b) + 128;
v = (0.4392*r -0.3678*g - 0.0714*b) + 128;
计算机中可以使用
2. YUV to RGB
r = 1.1644*y + 1.5960*v - 16;
g = 1.1644*y - 0.3918*u - 0.8130*v - 128;
b = 1.1644*y + 2.0172*u - 128;