Static Wikipedia February 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Web Analytics
Cookie Policy Terms and Conditions YUV - Wikipedia, the free encyclopedia

YUV

From Wikipedia, the free encyclopedia

Example of U-V color plane, Y value = 0.5, represented within RGB color gamut
Example of U-V color plane, Y value = 0.5, represented within RGB color gamut
Animation of all the possible RGB colors in the YUV color space. Time is Y, X-axis is U and Y-axis is V. (see image above) The black square delimits the (-0.5,-0.5)-(0.5,0.5) range.
Animation of all the possible RGB colors in the YUV color space. Time is Y, X-axis is U and Y-axis is V. (see image above) The black square delimits the (-0.5,-0.5)-(0.5,0.5) range.
An image along with its Y, U, and V components.
An image along with its Y, U, and V components.

The YUV model defines a color space in terms of one luma and two chrominance components. The YUV color model is used in the PAL, NTSC, and SECAM composite color video standards. Previous black-and-white systems used only luma (Y) information and color information (U and V) was added so that a black-and-white receiver would still be able to display a color picture as a normal black and white pictures.

YUV models human perception of color more closely than the standard RGB model used in computer graphics hardware, but not as closely as the HSL color model and HSV color model.

Y stands for the luma component (the brightness) and U and V are the chrominance (color) components. The YPbPr color model used in analog component video and its digital child YCbCr used in digital video are more or less derived from it (Cb/Pb and Cr/Pr are deviations from grey on blue-yellow and red-cyan axes whereas U and V are blue-luminance and red-luminance differences), and are sometimes inaccurately called "YUV". The YIQ color space used in the analog NTSC television broadcasting system is related to it, although in a more complex way.

Contents

[edit] Formulas

YUV signals are created from an original RGB (red, green and blue) source. The weighted values of R, G and B are added together to produce a single Y signal, representing the overall brightness, or luminance, of that spot. The U signal is then created by subtracting the Y from the blue signal of the original RGB, and then scaling; and V by subtracting the Y from the red, and then scaling by a different factor. This can be accomplished easily with analog circuitry. YUV (analog version of YUV) from RGB

Y = 0.299 * R + 0.587 * G + 0.114 * B
U = 0.436 * (B - Y) / (1 - 0.114)
V = 0.615 * (R - Y) / (1 - 0.299)

or

Y = (( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16);
U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128;

These formulae approximate the conversion between the RGB color space and YUV.

R, G, B, Y \in \left[0, 1\right]
U \in \left[-0.436, 0.436\right]
V \in \left[-0.615, 0.615\right]

From RGB to YUV:

Y = + 0.299 R + 0.587 G + 0.114 B
U = − 0.14713 R 0.28886 G + 0.436 B
V = + 0.615 R 0.51499 G 0.10001 B

From YUV to RGB:

R = Y + 1.13983 V
G = Y 0.39466 U 0.58060 V
B = Y + 2.03211 U

Or, using a matrix representation:

\begin{bmatrix} Y \\ U \\ V \end{bmatrix} = \begin{bmatrix} 0.299 & 0.587 & 0.114 \\ -0.14713 & -0.28886 & 0.436 \\ 0.615 & -0.51498 & -0.10001 \end{bmatrix} \begin{bmatrix} R \\ G \\ B \end{bmatrix}

\begin{bmatrix} R \\ G \\ B \end{bmatrix} = \begin{bmatrix} 1 & 0 & 1.13983 \\ 1 & -0.39465 & -0.58060 \\ 1 & 2.03211 & 0 \end{bmatrix} \begin{bmatrix} Y \\ U \\ V \end{bmatrix}

Two things to note regarding the RGB transformation matrix:

  • The top row is identical to that of the YIQ color space
  • If \begin{bmatrix} R & G & B \end{bmatrix}^{T} = \begin{bmatrix} 1 & 1 & 1 \end{bmatrix} then \begin{bmatrix} Y & U & V \end{bmatrix}^{T} = \begin{bmatrix} 1 & 0 & 0 \end{bmatrix}. In other words, the top row coefficients sum to unity and the last two rows sum to zero.

Note: this formula uses the more traditional model of YUV, which is used for analog PAL equipment; digital PAL and digital NTSC HDTV don't use YUV but YCbCr.

As most actual uses of RGB->YUV are in integer math, it's often convenient to use a fixed-point approximation.

Y := min(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235)
U := min(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240)
V := min(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240)

[edit] Luminance/chrominance systems in general

The primary advantages of luminance/chrominance systems such as YUV, and its relatives YIQ and YDbDr, are that they remain compatible with black and white analog television (largely due to the work of Georges Valensi). The Y channel saves nearly all the data recorded by black and white cameras, so it produces a signal suitable for reception on old monochrome displays. In this case, the U and V are simply discarded. If displaying color, all three channels are used, and the original RGB information can be decoded.

Another advantage of YUV is that some of the information can be discarded in order to reduce bandwidth. The human eye has fairly little color sensitivity: the accuracy of the brightness information of the luminance channel has far more impact on the image discerned than that of the other two. Understanding this human shortcoming, standards such as NTSC reduce the amount of data consumed by the chrominance channels considerably, leaving the eye to extrapolate much of the color. NTSC saves only 11% of the original blue and 30% of the red. The green information is usually preserved in the Y channel. Therefore, the resulting U and V signals can be substantially compressed.

However, this color space conversion is lossy. When the NTSC standard was created in the 1950s this was not a real concern since the quality of the image was limited by the monitor equipment, not the compressed signal being received. However today's modern television is capable of displaying more information than is contained in these lossy signals. To keep pace with the abilities of new technology, attempts have been made to preserve more of the YUV signal while recording images, such as S-Video on VCRs.

Instead of YUV, YCbCr was used as the standard format for (digital) common video compression algorithms such as MPEG-2. Digital television and DVDs preserve their compressed video streams in the MPEG-2 format, which uses a full YCbCr color space. The professional CCIR 601 uncompressed digital video format also uses YCbCr, primarily for compatibility with previous analog video standards. This stream can be easily mixed into any output format needed.

YUV is not an absolute color space. It is a way of encoding RGB information, and the actual color displayed depends on the actual RGB colorants used to display the signal. Therefore a value expressed as YUV is only predictable if standard RGB colorants are used (i.e. a fixed set of primary chromaticities, or particular set of red, green, and blue).

[edit] Confusion with YCbCr

YUV is often and mistakenly used as the term for YCbCr. However, they are different formats. YUV is an analog system with scale factors different than the digital YCbCr system.[1]

[edit] Types of sampling

To get a digital signal, YUV images can be sampled in several different ways; see chroma subsampling.

[edit] Converting from YUV to RGB

function RGB* YUV444toRGB888(Y, U, V); converts YUV format to simple RGB format and could be implemented using floating point arithmetic as:

  • YUV444
Y = 0.299R + 0.587G + 0.114B 
U = − 0.147R − 0.289G + 0.436B 
V = 0.615R − 0.515G − 0.100B

But floating point arithmetic is much slower than using [fixed point] arithmetic:

C = Y - 16
D = U - 128
E = V - 128

Using the previous coefficients and noting that clip() denotes clipping a value to the range of 0 to 255, the following formulas provide the conversion from YUV to RGB:

R = clip(( 298 * C           + 409 * E + 128) >> 8)
G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
B = clip(( 298 * C + 516 * D           + 128) >> 8)
  • YUV422

INPUT: Read 4 bytes of YUV (u, y1, v, y2 ) OUTPUT: Writes 6 bytes of RGB (R, G, B, R, G, B)

u  = yuv[0];
y1 = yuv[1];
v  = yuv[2];
y2 = yuv[3];

Using this information it could be parsed as regular YUV444 format to get 2 RGB pixels info:

rgb1 = YUV444toRGB888(y1, u, v);
rgb2 = YUV444toRGB888(y2, u, v);

YUV422 can also be expressed in YUY2 FOURCC format code. That means 2 pixels will be defined in each macropixel (four bytes) treated in the image.

  • YUV411
// Extract yuv components
u  = yuv[0];
y1 = yuv[1];
y2 = yuv[2];
v  = yuv[3];
y3 = yuv[4];
y4 = yuv[5];
rgb1 = YUV444toRGB888(y1, u, v);
rgb2 = YUV444toRGB888(y2, u, v);
rgb3 = YUV444toRGB888(y3, u, v);
rgb4 = YUV444toRGB888(y4, u, v);

So the result is we are getting 4 RGB pixels values (4*3 bytes) from 6 bytes. This means reducing size of transferred data to half and with quite good loss of quality.

  • YUV420p (and YV12)

YUV420p is a planar format, meaning that the Y, U, and V values are grouped together instead of interspersed. The reason for this is that by grouping the U and V values together, the image becomes much more compressible. When given an array of an image in the YUV420p format, all the Y values come first, followed by all the U values, followed finally by all the V values.

The YV12 format is essentially the same as YUV420p, but it has the U and V data reversed: the Y values are followed by the V values, with the U values last. As long as care is taken to extract U and V values from the proper locations, both YUV420p and YV12 can be processed using the same algorithm.

As with most YUV formats, there are as many Y values as there are pixels. Where X equals the height multiplied by the width, the first X indices in the array are Y values that correspond to each individual pixel. However, there are only one fourth as many U and V values. The U and V values correspond to each 2 by 2 block of the image, meaning each U and V entry applies to four pixels. After the Y values, the next X/4 indices are the U values for each 2 by 2 block, and the next X/4 indices after that are the V values that also apply to each 2 by 2 block.

Translating YUV420p to RGB is a rather involved process compared to the previous formats. Taking a 16 by 16 image for example, getting the RGB values for pixel (5, 7) where (0, 0) is the top left pixel would be done as follows. The character "/" implies integer division, meaning that if there is a remainder, it will be discarded.

Height = 16;
Width = 16;
YArraySize = Height * Width = 256;
Y = Array[7 * Width + 5];
U = Array[(7/2) * (Width/2) + 5/2 + YArraySize];
V = Array[(7/2) * (Width/2) + 5/2 + YArraySize + YArraySize/4];

RGB = YUV444toRGB888(Y, U, V);

Image:Yuv420.png
As shown in the above image, the Y, U and V components in YUV420 are encoded separately in sequential blocks. A Y value is stored for every pixel, followed by a U value for each 2x2 square block of pixels, and finally a V value for each 2x2 block. Corresponding Y, U and V values are shown using the same color in the diagram above. Read line-by-line as a byte stream from a device, the Y block would be found at position 0, the U block at position x*y (6*4 = 24 in this example) and the V block at position x*y + (x*y)/4 (here, 6*4 + (6*4)/4 = 30).

Raw YCbCr streams are often stored in files with extension ".yuv". Here are some freely available examples for research purposes: http://www.tkn.tu-berlin.de/research/evalvid/cif.html. These are simply a sequence of YCbCr frames serialized into a byte stream.

[edit] See also


[edit] External links

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu