Discussion:
RGB to YUV422 conversion
(too old to reply)
drulz
2007-02-15 13:43:28 UTC
Permalink
hi

Im looking for a formula on how to convert RGB to YUV422. All i can
find on the internet is conversion from RGB to YUV but not 422.

One more thing is im developing on an embedded device which doesnt
have support for 32 bit data type or even floating point, so im
looking for a fixed-point formula that uses shorts or char (16bit/
8bit) types. I have found a formula that uses unsigned char but i dont
have an idea on how to use it to convert RGB to YUV 422. The link is
bellow
http://msdn2.microsoft.com/en-us/library/ms893078.aspx

hope you can help me with this
Alastair M. Robinson
2007-02-15 16:38:50 UTC
Permalink
Hi,
Post by drulz
Im looking for a formula on how to convert RGB to YUV422. All i can
find on the internet is conversion from RGB to YUV but not 422.
The 422 part of YUV422 refers to the arrangement of the bytes in the
video frame, and the fact that U and V have only half the resolution of
Y - apart from that, Y, U and V are still calculated the same way.

Given a stream of RGB data: R1 G1 B1 R2 G2 B2 R3 G3 B3 R4 G4 B4...
A YUV422 output stream would look like this:

U1 Y1 V2 Y2 U3 Y3 V4 Y4 ...

Notice how for each pixel either U or V is ignored, alternating between
the two - thus only two bytes are used per pixel, instead of three.

All the best,
--
Alastair M. Robinson
Dave Martindale
2007-02-16 01:33:30 UTC
Permalink
Post by Alastair M. Robinson
Given a stream of RGB data: R1 G1 B1 R2 G2 B2 R3 G3 B3 R4 G4 B4...
U1 Y1 V2 Y2 U3 Y3 V4 Y4 ...
Notice how for each pixel either U or V is ignored, alternating between
the two - thus only two bytes are used per pixel, instead of three.
This implies that the U pixels that are output are offset one luminance
pixel pitch (half a chroma pixel pitch) from the V pixels that are
output. Is that correct?

I thought the U and V data that is output is from the same spatial
location.

Dave
Alastair M. Robinson
2007-02-16 02:35:47 UTC
Permalink
Hi,
Post by Dave Martindale
This implies that the U pixels that are output are offset one luminance
pixel pitch (half a chroma pixel pitch) from the V pixels that are
output. Is that correct?
I thought the U and V data that is output is from the same spatial
location.
You're probably right. In practice, I doubt it would make any visible
difference - and if you *really* wanted to do the job properly, you
could calculate U and V for both pixels and use the means of each. ;)

Using U and V from the same location is probably the most efficient
approach in terms of minimising calculations, anyway.

All the best,
--
Alastair M. Robinson
h***@arri.de
2007-02-18 20:15:53 UTC
Permalink
Hi,

Are you sure you want to do a RGB to YUV conversion? Or is it rather
YPbPr (or its digital representation as YCbCr) you are looking for?
Are you encoding SD or HD signals?
They use different color difference formulas and have different
standards for the for the chroma samples. ITU-R BT.601 says that the
CrCb samples should be co-sited with the odd Y-samples and SPMTE-274M
says that the CrCb samples should be co-sited with the even Y-
samples.
Get a document titled ITU-R BT.1361. There you will find optimized
integer coefficients for the luminance and color-difference formulas
and the description of a method how to derive them.
You should apply low-pass filtering when sub-sampling chroma to avoid
color aliasing. An averaging as suggested in one of the previous post
may result in poor image quality. I would recommend to use at least a
filter with 3 taps: 1/4, 1/2, 1/4.
In ITU-R BT.601 you will find some (rather general) guidelines for the
design of filters.

Regards

Harald
Post by drulz
hi
Im looking for a formula on how to convert RGB to YUV422. All i can
find on the internet is conversion from RGB to YUV but not 422.
One more thing is im developing on an embedded device which doesnt
have support for 32 bit data type or even floating point, so im
looking for a fixed-point formula that uses shorts or char (16bit/
8bit) types. I have found a formula that uses unsigned char but i dont
have an idea on how to use it to convert RGB to YUV 422. The link is
bellowhttp://msdn2.microsoft.com/en-us/library/ms893078.aspx
hope you can help me with this
drulz
2007-02-26 12:57:03 UTC
Permalink
Post by h***@arri.de
Hi,
Are you sure you want to do a RGB to YUV conversion? Or is it rather
YPbPr (or its digital representation as YCbCr) you are looking for?
Are you encoding SD or HD signals?
They use different color difference formulas and have different
standards for the for the chroma samples. ITU-R BT.601 says that the
CrCb samples should be co-sited with the odd Y-samples and SPMTE-274M
says that the CrCb samples should be co-sited with the even Y-
samples.
Get a document titled ITU-R BT.1361. There you will find optimized
integer coefficients for the luminance and color-difference formulas
and the description of a method how to derive them.
You should apply low-pass filtering when sub-sampling chroma to avoid
color aliasing. An averaging as suggested in one of the previous post
may result in poor image quality. I would recommend to use at least a
filter with 3 taps: 1/4, 1/2, 1/4.
In ITU-R BT.601 you will find some (rather general) guidelines for the
design of filters.
Regards
Harald
Post by drulz
hi
Im looking for a formula on how to convert RGB to YUV422. All i can
find on the internet is conversion from RGB to YUV but not 422.
One more thing is im developing on an embedded device which doesnt
have support for 32 bit data type or even floating point, so im
looking for a fixed-point formula that uses shorts or char (16bit/
8bit) types. I have found a formula that uses unsigned char but i dont
have an idea on how to use it to convert RGB to YUV 422. The link is
bellowhttp://msdn2.microsoft.com/en-us/library/ms893078.aspx
hope you can help me with this- Hide quoted text -
- Show quoted text -
i have tried averaging the Cb and Cr and it works fine with RGB with
even sized image (example 128x128 or 640x480). but my problem now is
odd width images example bitmap with 3x1 ( Which has actual size of
3x3x1) dimensions,which has a total width of 3x3 = 9; My question is
what would an RGB with an odd width be looked like when converted to
YUV422
example:
width x height = 3x1
size = 3x3x1 = 9

sample data: 123 456 789

what would it looked like in YUV422?

Loading...