RGB => YCbCr:
Y = 0.299r + 0.587G + 0.114b
CB =-0.1726r-0.3388G + 0.5114b + 128
Cr = 0.5114r-0.4282G-0.0832b + 128
Then we get YCbCr => RGB:
R = Y + 1.371 (Cr-128)
G = Y-0.6982 (Cr-128)-0.3365 (CB-128)
B = Y + 1.732 (CB-128)
8bit Conversion Equation
Y = (77r + 150g + 29B)> 8
CB = (-44r-87g + 131b)> 8 + 128
Cr = (131r-110g-21B)> 8 + 128
R = Y + (351 (Cr-128)> 8
G = Y-(179 (Cr-128) + 86 (CB-128)> 8
= Y-(179cr + 86cb)> 8 + (179 + 86) * 128)> 8
= Y + 133-(128 + 179cr + 86cb)> 8
B = Y + (443 (CB-128)> 8
To use look-up table, we can change to following format:
RGB => YCbCr:
We adjust a little of the factors to avoid saturation operation to improve performance
Y = (77r + 150g + 29B)> 8
CB = (128b-43r-85g)> 8 + 128 = (32768 + 128b-43r-85g)> 8
Cr = (128r-107g-21B)> 8 + 128 = (32768 + 128r-107g-21B)> 8
It needs 8 look-up tables:
T_77 [256], t_150 [256], t_29 [256], t_128 [256],
T_43 [256], t_85 [256], t_107 [256], t_21 [256]
YCbCr => RGB
R = saturation (Y + 1.371 (Cr-128 ))
G = saturation (Y-0.6982 (Cr-128)-0.3365 (CB-128 ))
B = saturation (Y + 1.732 (CB-128 ))
Here, "saturation (a)" means:
If (A> 255)
A = 255
Else if (a <0)
A = 0
It needs 4 tables:
Cr_1371 [256], cr_06982 [256], cb_03365 [256], cb_1732 [256]
YCbCr to RGB and RGB toycbcr