Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Hardboy on April 13, 2003, 01:58:55 PM

Title: RGB<->YUV Formulas?
Post by: Hardboy on April 13, 2003, 01:58:55 PM
Hi,

Does anyone know a set of RGB<->YUV formulas that work? I´ve found tons of them on the internet, but I haven´t found a set that gave the correct results - or just near the correct result..

Anyone?
Title: Re: RGB<->YUV Formulas?
Post by: lorddef on April 13, 2003, 02:13:44 PM
Well according to my multimedia lecture notes from uni, for PAL signals:

Y = 0.30R + 0.59G + 0.11B
U = 0.493 (B - Y) = -0.15R - 0.29G + 0.44B
V = 0.877 (R - Y) = 0.62R - 0.52G - 0.1B

hope that helps.
Title: Re: RGB<->YUV Formulas?
Post by: Hardboy on April 13, 2003, 02:42:29 PM
Quote
hope that helps.


Depends. Do you have the reverse formulas?
Title: Re: RGB<->YUV Formulas?
Post by: lorddef on April 13, 2003, 03:38:28 PM
just do a bit of algebra to transpose them around, that'll give you the reverse formulas.
Title: Re: RGB<->YUV Formulas?
Post by: Hardboy on April 13, 2003, 04:06:07 PM
I know that, but i´m too lazy...
Title: Re: RGB<->YUV Formulas?
Post by: lorddef on April 13, 2003, 04:20:55 PM
it'd take all of 5 minutes
Title: Re: RGB<->YUV Formulas?
Post by: iamaboringperson on April 14, 2003, 05:13:11 AM
i wish i knew how the chroma signal in pal worked....
i know about luma
i just want to know how red and blue fit in
 :-)
Title: Re: RGB<->YUV Formulas?
Post by: tonyw on April 29, 2003, 12:38:47 AM
If there's one thing I know about, it's PAL TV theory. So, to be boring . . .

The RGB inputs from the source are combined to form a luminance signal Y=0.59*G + 0.3*R + 0.11*B. That provides a B&W signal that is important for back-compatibility. The colour signals are then added to that.

The colour signals added to the luminance signal always deteriorate the displayed luminance signal to some extent. So, it is designed that the colour signals become zero when there is no colour, ie in B&W areas, where the eye can see finest detail. To do that, we transmit colour difference signals, that are zero in B&W areas.

The colour (hue) range is arranged as a circle, with blue on the left, yellow on the right, red up the top and green at the bottom. No colour at all is the dot in the middle, full saturated colour is the point on the circle at the right angle. Any point within the circle represents less saturated (washed out) colour of that angle (hue) and radius (saturation). Such a point can be described by the radius and angle, or more conveniently, by the x and y co-ordinates, U (horizontal) and V (vertical). +V is red-magenta, -V is green (ish), +U is blue, -U is yellow (ish).

The U signal is generated by (B-Y), V by (R-Y). It's these signals that are then encoded into the chrominance signal and added to the luminance signal to make a composite signal to transmit.

To make the chroma signals
(1) easy to detect in the receiver;
(2) less likely to interfere with the luminance;
(3) independent of each other;
they are modulated onto a colour subcarrier that is high in the luminance passband (4.43 MHz). Each is modulated onto a subcarrier that is 90 degrees out of phase with the other. A synchronous detector in the receiver will not hear any of the other signal, so you have two independent channels. To reduce interference with the luminance, the two signals are transmitted with the carrier signal suppressed, so that in B&W areas, there is nothing but the B&W luminance signal.

This whole system was designed by the American National Televison System Committee (NTSC) in the 1950s. Although the details have been improved by the PAL system, the basic principles have remained. It truly is one of the great inventions of electronics.

tony
Title: Re: RGB<->YUV Formulas?
Post by: iamaboringperson on April 29, 2003, 12:44:41 AM
WOW! thankyou! :-o  :-o  :-o

thats just ONE of lifes mistries out of the way...  ;-)
Title: Re: RGB<->YUV Formulas?
Post by: JetRacer on April 29, 2003, 10:10:10 AM
Unrelated, but if anyone want to convert color graphics to grey:

R 0.299
G 0.587
B 0.114

R+G+B = 1.0

I found this out when I wrote a Floyd-Steinberg dithering routine. Without evaluating the error of the color selection properly, the dithered image would become slightly green toned.

Another issue was that a 50% b/w pattern would become 70.7% grey (1/sqrt(2)), not 50% grey. So I had to correct that too. AFAIK, I'm the only one that have adressed that issue (that statement includes Photoshop, GIMP and NetPBM).
Title: Re: RGB<->YUV Formulas?
Post by: Jaruzel on April 29, 2003, 10:14:08 AM
@tonyw

Yes, wow. For once something I normally find dry and complex, easily explained!

You should put up a webpage with a few diagrams, help the world out a bit ;-)

-Jar.