Comparison between RGB and YUV

Source: Internet
Author: User
Tags color gamut

Http://blog.csdn.net/qfnu08zzr/article/details/6763159

 

RGB Principle

RGB is designed based on the principle of color light. Generally speaking, the color mixing method is like red, green, and blue lamps, when their light is overlapped, the colors are mixed, while the brightness is equal to the sum of the brightness (the brightness of the two lights !), The greater the blending brightness, the greater the addition brightness.

Colored light can be diluted and brightened by colorless light. If the blue light and the white light meet each other, the result is a brighter light blue light. After knowing the mixing principle, it is easy to set the color in the software.

Red, green, and blue lights are superimposed on each other. The brightest overlapping area in the center is white. Addition and mixing features: the brighter the overlapping area.

Red, green, and blue channels each color is divided into 255-level brightness. When 0, the "light" is the weakest-it is switched off, and the "light" is the brightest at 255. When the three colors are both non-color gray colors, and the three colors are 255, the brightest white, and 0 is black.

RGB colors are called bonus colors because you can produce white by adding R, G, and B Together (that is, all the light is reflected back to the eyes. Bonus colors are used for lighting, television, and computer displays. For example, a display emits light in red, green, and blue colors. The vast majority of the visual spectrum can be represented as a mixture of red, green, and blue (RGB) colors at different proportions and intensity. If these colors overlap, blue, red, and yellow are generated.

The encoding method for a color is referred to as "Color Space" or "Color Gamut ". In the simplest words, the "Color Space" of any color in the world can be defined as a fixed number or variable. RGB (red, green, and blue) is only one of the many color spaces. With this encoding method, each color can be represented by three variables-red green and blue intensity. R GB is the most common method for recording and displaying color images. However, it lacks good compatibility with early black/white display systems. Therefore, the common practice adopted by multiple electronic and electrical appliance manufacturers is to Convert RGB to YUV to maintain compatibility, and then switch back to the RGB format as needed, to display color images on computer monitors.

Rgb24 indicates that the R, G, and B components each occupy 8 digits.

Rgb32 indicates that the four components R, G, B, And a each occupy 8 digits.

When you edit the color in the appearance of Windows desktop properties, there are two ways to edit the color: YUV and RGB.

YUV is mainly used to optimize the transmission of color video signals, so that it is backward compatible with vintage black and white TVs. Compared with RGB video signal transmission, RGB requires three independent video signals to be transmitted at the same time ). "Y" indicates the brightness (luminance or Luma), that is, the gray scale value, while "u" and "V" indicate the color (chrominance or chroma ), it describes the image color and saturation, and is used to specify the color of a pixel. The "brightness" is established through the RGB input signal by overlapping specific parts of the RGB signal. "Color" defines two aspects of color-tone and saturation, expressed by Cr and CB respectively. Cr reflects the difference between the red part of the GB input signal and the brightness value of the RGB signal. CB reflects the differences between the blue part of the RGB input signal and the brightness value of the RGB signal.

The importance of using YUV color space is that its brightness signal y is separated from the color signal u and v. If only the Y Signal component is used, but not the U or V component, the black and white gray images are displayed. The color TV uses the YUV space to solve the compatibility problem between the color TV and the black and white TV with the Brightness Signal y, so that the black and white TV can also receive the color TV signal.

The conversion formula between YUV and RGB is as follows (the RGB value ranges from 0 to 255 )︰

Y = 0.299r + 0.587G + 0.114b

U =-0.147r-0.289G + 0.436b

V = 0.615r-0.515g-0.100b

R = Y + 1.14 V

G = Y-0.39u- 0.58 V

B = Y + 2.03u

In DirectShow, common RGB formats include rgb1, rgb4, rgb8, rgb565, rgb555, rgb24, rgb32, and argb32; common YUV formats include yuy2, yuyv, yvyu, uyvy, ayuv, y41p, y411, y211, if09, iyuv, yv12, yvu9, yuv411, and yuv420.

The main sampling formats are YCbCr, and YCbCr. YCbCr is commonly used. It means that each vertex stores an 8-bit brightness value (that is, the Y value), and each 2x2 points stores a Cr and CB value, the image does not feel much changed to the naked eye. Therefore, the original RGB (R, G, and B are all 8bit unsigned) models, where 8x3 = 24 bits (such as the first graph) is required for a single vertex (after full sampling, YUV still accounts for 8 bits ). After sampling at, the current average only needs 8 + (8/4) + (8/4) = 12 bits (4 points, 8*4 (y) + 8 (u) + 8 (v) = 48 bits), with an average of 12 bits for each vertex (such as the second figure ). In this way, the image data is halved.

The above only provides a theoretical example, which may be different in actual data storage. Below are several specific storage formats:

(1) YUV 4: 4

The sampling rate of the three channels of YUV is the same. Therefore, in the generated image, the information of the three components of each pixel is complete (each component is usually 8 bits). After 8 bits quantization, each uncompressed pixel occupies 3 bytes.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 v3

(2) YUV

The sampling rate of each chromatic aberration channel is half of the brightness channel, so the color sampling rate in the horizontal direction is only half. For non-compressed 8-bit quantization images, each macro pixel consisting of two adjacent horizontal pixels occupies 4 bytes of memory.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 Y1 V1 Y2 U2 Y3 v3

The mapped pixel is: [y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]

(3) YUV

The color sampling at is a sample of the color in the horizontal direction. This is acceptable for low-end users and consumer products. For non-compressed 8-bit quantization videos, each macro pixel consisting of four adjacent horizontal pixels occupies 6 bytes of memory.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 Y1 Y2 V2 Y3.

The mapped pixel is: [y0 U0 V2] [Y1 U0 V2] [Y2 U0 V2] [Y3 U0 V2]

(4) yuv4: 2: 0

Doesn't mean only y, CB, and no Cr component. It means that for each scanned line, only one color component is stored at a sampling rate of 2 to 1. The adjacent scan lines store different color components. That is to say, if the line is, the next line is, And the next line is... and so on. For each color component, the sampling rate in both the horizontal and vertical directions is, so the color sampling rate is. For non-compressed 8-bit quantization videos, every macro pixel consisting of 2x2 two rows and two columns of adjacent pixels occupies 6 bytes of memory.

The following eight pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

[Y5 U5 V5] [y6 U6 V6] [y7u7 V7] [Y8 u8 V8]

The stored code stream is y0 U0 Y1 Y2 U2 Y3 Y5 V5 y6 y7 V7 Y8.

The mapped pixel is: [y0 U0 V5] [Y1 U0 V5] [Y2 U2 V7] [Y3 U2 V7]

[Y5 U0 V5] [y6 U0 V5] [y7u2 V7] [Y8 U2 V7]

Comparison between RGB and YUV)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.