Question

From .ppm image, I extracted R,G,B data and saved following structures:

                       RGB RGB RGB RGB RGB RGB RGB..........

corresponding to each pixel position.

Then I used formula to convert R,G,V into Y,U,V.With each pixel, I obtained YUV correspondingly.

                     R0G0B0->Y0U0V0 , R1G1B1 ->Y1U1B1, ........

I saved data following YUV422 Data Format:The YUV422 data format shares U and V values between two pixels. As a result, these values are transmitted to the PC image buffer only once for every two pixels.

                              R0G0B0R1G1B1->Y0UY1V

a,How to calculate U and V from U0,U1 and V0,V1????????

b,In my case , I used this formula:

                         U=(U0+U1)/2;     V=(V0+V1)/2;

Obtained data was saved following structure to create .yuv file:

                    YUYV YUYV YUYV YUYV YUYV YUYV......

But when I used YUV tools to read new .yuv file, that image is not similar to original image. What did I do wrong here ????

Was it helpful?

Solution

The formula what you have employed is the right one. But a small correction in the arrangement of output data of YUV422 Planar (Horizontal sampling). Luminance data of Width * Height size followed by Cb data of Width * Height/2 and Cr data of width * Height/2.

It should be as mentioned below:

[Y1 Y2 Y3 ... (Width * Height)] [Cb1 Cb2 .... (Width * Height/2)] [Cr1 Cr2 ...(Width * Height/2)]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top