Basic Image Processing (pixel, RGB, YUV etc .)

Source: Internet
Author: User
Tags color gamut

For ease of recording, the following terms are equivalent:

1. Color Space = Color Gamut = color model or Method

2. Sampling Method = Recording Method of (image) information elements = Recording Method of Information in the Data Structure

I. What are pixels? Pixels are the data structures used to describe image information elements.

To describe an image as a collection of information elements, we must first model it and use a Data Structure to represent information elements. As a result, after modeling, the image becomes a collection of data structures (structs). Now a name for this data structure is pixel. Therefore, pixels are not a specific physical quantity, it is just an abstract data structure.

2. color information can be recorded in the pixel data structure (because the image is composed of different colors). If the color is represented by RGB color space, then a pixel must be divided into three sub-pixels (or three sub-pixels): Red, green, and blue ). If the color space YUV is used to represent the color, it can be divided into Y (brightness-luminance), UV (color is also called chromatic aberration, and the color is divided into two independent signal storage, U (CB -- blue, its value = CB-y), V (Cr -- red, its value = cr -- y )).

1. It is necessary to explain YUV here. If RGB uses a combination of three primary colors to indicate the color, how does YUV represent the color? The answer is --- expressed by brightness and chromatic aberration (brightness is black-white signal, and color is color signal)

Scientific Discovery: people are more sensitive to brightness than to color. Therefore, when we store pixels, we store more brightness and less color to reduce storage space.

YUV has three sampling methods: yuv444, yuv422, and yuv420.

If you use the sampling method in the hand-painted three, it can be represented by Y in square brackets. UV is regarded as a whole and drawn into a circle in Y. So for eg444, draw four boxes (Y) and draw a circle in each box.

(1) yuv444 records four brightness records and then records four U and four V respectively.

In the figure, the background (black and white) indicates the brightness, and the green one indicates the color.

This storage method is mainly used to ensure the quality of the image (to prevent image quality reduction during processing ).

Four pixels are collected. Their data structures are as follows: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3: y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 v3

(2) yuv422, two brightness values share one color

Most people cannot tell the difference between 444 and 422.

Likewise, the three components in the data structure are collected in four pixels: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

Based on the principle that two adjacent pixels share a UV color pair, the stored bitstream is y0 U0 Y1 V1 Y2 U2 Y3 V3.

Re-map the bitstream (re-construct the pixel). The resulting pixel is: [y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]

(3) yuv411: Forgive me for not finding his picture, but it is actually very simple. 411 and 420 can be associated with memories,

420 is a UV of 2*2 pixels, while 411 is a UV of 4 consecutive pixels in the horizontal direction.

For 4 pixels [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

411 the sandwich method is used. One color (U or V), U, and V are clamped between two brightness y values. The first U, the second V, and the fourth y share the same UV.

Therefore, the bit stream is: y0 U0 Y1 Y2 V2 Y3

After the ing, [y0 U0 V2] [Y1 U0 V2] [Y2 U0 V2] [Y3 U0 V2]

(4) yuv420

Note: although the ratio of Y, U, and V is 420, it seems that it should be 4 Y, 2 U, and 0 V, neither of which is the same as that of v, but this is not the case.

It actually means that for each scanned line, only one color component (First U and then V) is taken, and the ratio of the color component to the brightness is, the above two y instances share one U or v. 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.

Scanning line:

Collect 8 pixels,

[Y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3] [Y4 U4 V4] [Y5 U5 V5] [y6 U6 V6] [y7 u7 V7] storage code stream: y0 U0 Y1 Y2 U2 Y3 Y4 V4 Y5 y6 V 6 y7 re ing: [y0 U0 V4] [Y1 U0 V4] [Y2 U2 V6] [Y3 U2 V6] [Y5 U0 V4] [y6 U0 V4] [y7u2 V6] [Y8 U2 V6]

//-----------------------------------------------------------------

Well, the YUV format is similar here. Another point is that the YUV data (processed by software or hardware) needs to be further processed.

The YUV format can be packaged in two ways: A, packed format packaging format B, planar format plane format

A. Packed format, which encapsulates y and UV into a package. The specific implementation is to store them in an array. Yuy2 is the packaging format, and its YUV ratio is 422

BAnd planar format, which respectively encapsulate and package y, U, and V to form three plane (plane). The specific implementation is to exist in three arrays respectively. Yv12 is in flat format, and its YUV ratio is 420.

2. Compare different color spaces (only through comparison can we know why there are so many color representations)

(1) RGB and RGB color spaces are designed for hardware. Generally, the color information in pixels collected by devices is stored by dividing them into R, G, and B. RGB Images occupy a large amount of storage space, so they are suitable for display systems and are not suitable for image processing.

In addition, the RGB color is a direct sampling of real food, so the image will be affected by light, shadow and other factors, while the RGB space, color (red, green, and blue) will be affected by the brightness, if the brightness changes, the color will change;

In addition, the transmission of the RGP image requires three channels to transmit the r \ G \ B3 Signals respectively so that the image can be displayed at the other end.

(2) YUV: in this format, Y \ U \ v are respectively encoded and stored, so time-sharing can be used for transmission over a channel, this is also the most important feature of YUV .; ,

III,

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.