anandkumarcr
Junior Member level 1
HI,
I needed a clarification in the conversion of RGB -> YCbCr and resulting YCbCr back to RGB.
The following is the formula I am using to convert RGB -> YCbCr.
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16..................(1)
Cb = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128..................(2)
Cr = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128....................(3)
And to get back the original RGB from YCbCr I am using the following :-
R = 1.164(Y - 16) + 1.596(Cr - 128)..........................(4)
G = 1.164(Y - 16) - 0.813(Cr - 128) - 0.391(Cb - 128).................(5)
B = 1.164(Y - 16) + 2.018(Cb - 128)....................(6)
However I am getting the following outputs for the following inputs:-
Original R = 187
Original G = 146
Original B = 69
From equations (1),(2),(3) above
Y = 144
Cb = 37
Cr = 51
And on reverting back the YCbCr to obtain the original RGB according to equations (4),(5),(6) -I am getting
Obtained R = 185
Obtained G = 165
Obtained B = -34
Though the obtained RGB is correct according to the calculations, it does not make any sense that it is not equal to the original RGB input and even worse - obtained RGB attains negative values at times.
Could anybody please point out any mistakes or any steps that need to be corrected ?
Thank you
I needed a clarification in the conversion of RGB -> YCbCr and resulting YCbCr back to RGB.
The following is the formula I am using to convert RGB -> YCbCr.
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16..................(1)
Cb = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128..................(2)
Cr = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128....................(3)
And to get back the original RGB from YCbCr I am using the following :-
R = 1.164(Y - 16) + 1.596(Cr - 128)..........................(4)
G = 1.164(Y - 16) - 0.813(Cr - 128) - 0.391(Cb - 128).................(5)
B = 1.164(Y - 16) + 2.018(Cb - 128)....................(6)
However I am getting the following outputs for the following inputs:-
Original R = 187
Original G = 146
Original B = 69
From equations (1),(2),(3) above
Y = 144
Cb = 37
Cr = 51
And on reverting back the YCbCr to obtain the original RGB according to equations (4),(5),(6) -I am getting
Obtained R = 185
Obtained G = 165
Obtained B = -34
Though the obtained RGB is correct according to the calculations, it does not make any sense that it is not equal to the original RGB input and even worse - obtained RGB attains negative values at times.
Could anybody please point out any mistakes or any steps that need to be corrected ?
Thank you