I encode a video codec using a JPEG compression technique for each frame. So far, I have already encoded YUV, DCT and quantized DCT (encoding and decoding). I have already encoded the encoding YUV422, but I do not understand how to do the opposite (decoding).
To calculate my YUV for each pixel, I used the following equations:
Coding:
Y = 0.299 * R + 0.587 * G + 0.114 * B U = -0.1687 * R - 0.4187 * G + 0.5 * B + 128 V = 0.5 * R - 0.4187 * G - 0.0813 * B + 128
Decoding:
R = Y + 1.402 * (V - 128) G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128) B = Y + 1.772 * (U - 128)
These equations do the perfect job.
Now, to perform the encoding with downsampling, I take my image encoded in YUV, and I calculate the sum of two adjacent pixels, and I divide the result by 2. The result is set for 2 pixels.
Example:
For simplicity, I'll take a pixel value from 0 to 255 (not using RGB components).
Below: 2 examples with the same result.
Pixel_1 = 15, Pixel_2 = 5 -> (Pixel_1 + Pixel_2) / 2 = 10 Pixel_3 = 10, Pixel_4 = 10 -> (Pixel_3 + Pixel_4) / 2 = 10
If I apply this equation to all the pixels of my YUV image, I get a new image, but this time is encoded in the YUV422 subsample.
It is so interesting how I can return a YUV image from a YUV422 image. My example just above shows that it is impossible to return the original YUV image, because there are many combinations that lead to the same result (here 10). However, I think there is a way to get, give or take several, the same original YUV pixel values. Can anyone help me please? I am really lost. Many thanks for your help.