REDnet.nl
REDnet.nl
Creatief Visie Interactie   [=] EnglishSwitch to English Home
Artikelen
(2 reacties) toon reacties Digital Video and the YUV Color Model (Vr 2 november '07 om 13:53 pm) Niet beschikbaar in het Nederlands, sorry!
Chances are you don't care about the technology that holds your video. And that's probably why you are not reading this. The truth is that it matters. I've had experiences with projects where people don't understand certain limitations but applaude my ability to bend them. It's simple knowledge that makes one understand what happens why and how much can be done about it. Therefore, I cannot restrain myself from saying the motto of smartasses: Knowledge is power.

The goal of this first Digital Video article is to prevent any frowny face in the world from happening after any color model related thoughts are presented in a discussion about digital video.

For starters, why did mankind torture itself by making complicated color models anyway? Read on and you'll get the basic idea.

Basic color models - The easy part



You know the RGB color model. It's how your computer calculates colors that are on your screen. Other color models you might have come across during your Photoshop sessions are LAB and CMYK. Each color model has a purpose.

RGB


Additive color model
Additive color model
The color model we've become accustomed to. The simple fact that we perceive color through nerves called 'cones' in our eyeballs' retina's which individually absorb either red, green or blue light - the three primary colors in additive color mixing which is used in every (color) monitor, television and beamer in the world - might illustrate why this model is so mainstream. I don't have to explain that you can get any color by mixing those three colors of light. No matter what color model tricks are performed, in real life, everything is in the RGB model.


CMYK


Substractive color model
Substractive color model
When people started painting back when, it was known that dye doesn't mix as well as light. That's because a colored surface doesn't add it's own color to the mix, it substracts everything except itself. Cyan, Magenta and Yellow were found to be primary colors in substractive colormixing. This means that when you want a certain color, you mix cyan, magenta and yellow so that all colors you don't want get absorbed by the dye.
What about the K?
Even though our technology rules, we still can't make perfect dye. All paint mixed together still leaves a little bit of color unabsorbed, leaving a dark turdish or greyish color. That's why we added blacK. To make a theoretically black mixture actually look black. Also, it can save you massive amounts of colored ink.
(image exaggerated)


For example, cyan absorbs red and magenta absorbs green. So how would you make the color blue? Exactly, by mixing the red and green absorbants cyan and magenta.



LAB


Lab is a color model that maps the XYZ color space - the mother of all colorspaces derived from eyeball-science - to gamma compressed values. This means that stepping through the color scale provides perceptually equal color changes in stead of theoretically equal changes (which are perceptually logaritmic) like it is in XYZ. Lab is worth noting because XYZ is, even though no one's heard of it these days. And because L (for Lightness) is the color's luminance separated from chrominance (chroma) channels a and b (which are color-opponent channels, where two colors are mapped on a single center-biased channel); you'll notice later on that the YUV model works sort of the same. Lab is just a little bit more complicated because a and b depend on each other while U and V only depend on Y. That's why I cannot make an L + a + b = RGB image with colors that make sense, but here is the L + (a*b) representation:


The RGB model simply mixes the three primary colors. Webdesigners sometimes have dreams about these bars.

Enough. Let's talk about video



From photoshop to video compositing suites and computer generated graphics, in the computerscene everything works with RGB. However, video in MPEG-2 (dv, hdv, cable tv, dvd, satellite, digital antenna, etc.) or MPEG-4 (DivX, XViD, AVC, VC-1, .h264, etc.) is encoded with the YUV color model. YUV, like Lab, is luminance separated from chrominance. Why this model? Read on.

YUV



Back in the '30s, people were watching television in black & white. However, they could imagine that color television would be cool. So they invented it, and wanted ofcourse to replace their black & white transmissions with colored ones. Unfortunately, the millions of black & white televisions could only handle a single channel and failed to make a clear picture out a RGB video signal.

Until in 1938 Georges Valensi invented a color model to transmit a colored signal so that both color and black & white televisions could produce a clear picture. This was done by extracting a pure black & white channel (Y) without the need for extra bandwidth.

The Y channel is build by a certain mixture of the R, G and B channels. The UV components each represent two colors. Imagine the center value being an axis; values can go above and below this axis. That's because the formula substracts certain percentages of R and G from the center value, and adds B (in the case of U - swap R and B for V).


YPbPr


When the theoretical YUV channels are converted to analog signals, some gamma correcting happens to the initial RGB channels so that not too much of the signal is wasted on intensities we cannot distinct anyway. The result is called R'G'B' from which Y' (luma) (= gamma-corrected Y (luminance)) is derived. The analog representations of UV are called PbPr. Pb and Pr are respectively B'-Y' and R'-Y'. This analog color space, called "Y'PbPr", is a colorspace mapped to the YUV color model.

Luma is not Luminance
In video world, channels are always gamma-corrected internally. That's why Y'PbPr and R'G'B' are called YPbPr and RGB again. This was decided by the rulers of the world to make things more confusing.

Y calculations
B'-Y' is the same as "the formula substracts certain percentages of R and G from the center value, and adds B (in the case of U)." That's because Y' already contains amounts of RGB, remember?

Gamma corrections
The individual channel gamma corrections and the way colors are mixed for Y' is defined by the ITU-R sector. The best known specifications are BT.601 (for standard video) and ITU-R BT.709 (for high defenition video). Indeed, high defenition video is a different mix. Mostly because after all these decades, our monitor and television equipment have changed. In order to keep perceptual linearity between color variations, the gamma corrections had to be changed too. The specifications manage a whole lot of other boring technical stuff, too. But when your NLE starts whining about 601 and 709, I promise you it's about the colortalk only.

Certain Mixture?
No, to get Y we don't just add RGB. Did you know there are almost twice as many green receptors in a Digital Camera's CCD as there are Red or Blue ones? We are born green-horny. You don't see it, but more than half of all color information you perceive is represented by green. It makes sense to let green play a major role in the Y channel. The BT.601 recepy for luma is 30% red, 59% green and 11% blue. Funny thing we're still able to see smurfs as good as frogs, eh? Anyway, take your digital still camera, shoot something with many colors in not ideal lighting conditions and check the channels in photoshop. Unless you got separate CCDs (expensive camera), you'll notice green looks hot and tight, while blue represents a cheap ass noisy as hell camera.


YCbCr


YCbCr loses some detail compared to (digital) RGB. For example, RGB(0,0,0) equals Y'(16) and RGB(255,255,255) equals Y'(235). There's room for blacker black and whiter white. These are called superblack and superwhite.
YCbCr is the digital version of YPbPr. The signals are now stored in bytes in stead of voltages. Now this is the familiar color space used in all broadcasts and almost all video you see on the computer. It's mandatory for DV, HDV and MPEG.

Cb goes from some sort of yellow to bluish, and Cr goes from greenish to Reddish. When you overlay these channels on top of the Y' channel, you recreate the exact same RGB image!


Is that even possible?
Aren't you thinking like: "You cannot possibly get all colors back from these off colors?" if so, just think again while remembering that Y holds all data, including almost 60% of the green channel. So when the overlay multiplies or screens itself on the Y channel, the luma is arranging some adding and subtracting of RGB, making clear colors possible:


Note that in stead of overlaying the CbCr channels, the computer inverts the formula that does the YUV-conversion trick but in effect it's the same thing. The computer prefers calculations while humans prefer visual confirmation to see the logic behind an idea.

Also note that if you think of overlaying itself literally (as in Photoshop layers), luma is stacked on top of chroma because the grey in chroma would mess with the final luminance of the image in RGB processing mode.


Why YCbCr in stead of RGB?


Indeed, the YUV color model has lost it's use in the digital color era. In fact, due to the rescaling to allow for supers and synchronisation bits, the actual picture carried by a YCbCr signal is inferior to that of RGB. Why live on an inheritance when it's worse compared to other techniques? Let me explain.

Human vision is very sensitive to brightness. The contrasting black and white image means so much more than a bunch of colors. We think something is white when in fact it is yellow or blue. We don't even notice that the outer parts of our field of vision can only be perceived in black and white. Since chromatic sensibility is badly implemented in human vision, we can do without quite a lot of the chromatic data.

The YUV model can be concidered similar to the way human vision works, since it separates the important data (luma) from the less important data (chroma). And this separation makes some brutal compression possible. Subsample (divide) the resolution of a movie you're watching, and you'll immediately want your money back. But if you subsample just the chromatic data, no one will hardly notice! This is done extensively in all video you see.


Chroma subsampling


Subsampling is expressed as a per-channel ratio. Take an RGB signal; the subsampling ratio will be 4:4:4. This means: For every line, when 4 pixels of Red are sampled, 4 pixels of Green and Blue will be sampled. Because subsampling is usually applied to the YUV model, the 2nd and 3rd digit represent samples of respectively Cb and Cr for each [1st digit] samples of Y'. Sometimes the 3rd channel will be 0. This means "as 2nd channel, same for vertical subsampling, effectively translated to a vertical subsampling ratio of 2 for 4:2:0.

SubsamplingNameUsed in
4:4:4 YV24/RGBhigh-end YCbCr or RGB
4:2:2 YUY2/YUYV/YV16Digital Betacam, DVCPRO50, DVCPRO HD, Digital-S, D1
4:2:0 YV12MPEG-2, MPEG-4*, DVD, PAL DV, DVCAM, HDV, MJPEG, VC-1
4:1:1 YV411DVCPRO, NTSC DV, DVCAM
* Exceptions possible

Other compression


Just leaving out pixels is quite brutal, but it's a massive data saving start. Next step is quantizing the chroma data. In this step, the color scale is made smaller so more data can be thrown away to make some form of encoding (like Huffman or Entropy) more efficiënt. Note here that these compression techniques are considered lossless, but in order to optimize them we throw away a lot of data. (And I'm not even mentioning 'real' compression.) To make the numbers even smaller, they are stored as the difference from Y.

Ofcourse, MPEG is a lot of fun, but all I want to do is reach a point where you understand how we became hooked on YUV in video. You see, because otherwise we could never fit so many tv channels on the cable, video on a affordable tape, or a two hour movie on a single CD (those things used to store 80 minutes of audio).

Video example



Okay, here's a small video that illustrates the workings of the YCbCr color space.

[This object requires Flash]

Final Words


Remember this. You'll understand why you cannot go back and forth between RGB and YUV just like that, why your bluescreen footage has jagged lines, why a greenscreen is better, why some codecs suggest you convert to YUV for compression, why stills from your movie camera aren't as good as same resolution digital photographs, why colored titles look more blurred on youtube than white ones and trust me you can figure out a whole lot more by knowing this.

I hope you enjoyed reading this. I'm no professor though, and therefore sorry if I wasn't accurate at one time or another.

Feel free to leave a message.
Reageer (2 reacties) toon reacties
Home
Creatief
Visie
Interactie
 
~Home~


Laatste reacties
[6/8] Twitter sucks big time
[8/7] Massive transcodeless YUV to RGB project conversion made easy
[25/6] Redsandro.com is up
[28/3] Broken
[26/1] HP Officejet d145 hacken
[2/11] Windows XP File Sharing uncovered
[11/5] NH²Cl
[11/2] Albert Heijn Klantenservice is een idiocratie
~Creatief~


Onderdelen
Red photoshed
Classics
RED @ RED
Interdimensionals
RED's Place 3
The Radon clan
RED's Place 2
~Visie~


Artikelen
[8/1] Windows 7, SSH daemons and Cygwin
[31/12] I'ma stick to Ubuntu, sorry!
[15/4] Rid your consoles- XBMC and Arcade Browser are here!
[5/2] Import those frickin' contacts on your Nokia N Series
[30/11] Onhandigheden en ambtenarij van de IB-Groep
Columns
[9/1] C1000
[3/4] Albert Heijn Klantenservice is een idiocratie
[10/3] What Really Boils My Blood II
[16/2] Je beste vriend de politie
[4/2] Kanker NS
~Interactie~


Gastenboek
Plaats bericht
Contact