Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advantages of YUV in android

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what are the advantages of YUV in android", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the advantages of YUV in android" article.

Before introducing the YUV format, let's first introduce the RGB format that we are familiar with.

RGB

RGB stands for red (R), green (G) and blue (B), that is, three primary colors, which can be superimposed in different proportions to produce different colors.

For example, a picture of 1920 by 1280 represents 1920 by 1280 pixels. If RGB coding is used, each pixel has three primary colors: red, green and blue, in which each primary color occupies 8 bytes and each pixel occupies 24 bytes.

Then, a 1920 * 1280 image takes up 1920 * 1280 * 3 / 1024 / 1024 = 7.03MB storage space.

YUV

YUV coding uses luminance and chromaticity to represent the color of each pixel.

Where Y represents the brightness (Luminance, Luma), that is, the grayscale value.

U and V represent chromaticity (Chrominance or Chroma) and describe hue and saturation.

YCbCr is actually a scaled and offset replica of YUV. The meaning of Y is the same as that of Y in YUV, and Cb,Cr also refers to color, but it is different in the way of expression. YCbCr where Y is the luminance component, Cb is the blue chromaticity component, and Cr is the red chromaticity component.

Advantages of YUV

For the image represented by YUV, the Y and UV components are separated. If there is only a Y component without UV separation, then the image represents a black-and-white image. Color TV sets use YUV images to solve the problem of compatibility with black-and-white TV sets, so that black-and-white TV sets can also accept color TV signals.

The sensitivity of human eyes to chromaticity is lower than that to luminance. The main reason is that there are more retinal rod cells than retinal cone cells, in which the role of retinal rod cells is to recognize brightness, and the role of retinal cones is to identify chromaticity. Therefore, the eye's resolution of brightness is finer than that of color.

Using this principle, the chromaticity information can be reduced a little bit, which can not be detected by the human eye.

Therefore, not every pixel needs to contain Y, U, V three components. According to different sampling formats, each Y component can correspond to its own UV component, or several Y components can share UV components. Compared with RGB, it can save a lot of storage space.

YUV sampling format

There are three main sampling methods for YUV images:

YUV 4:4:4 sampling

YUV 4:2:2 sampling

YUV 4:2:0 sampling

YUV 4:4:4

YUV 4:4:4 means that the sampling rate of Y, U and V is the same, that is, the three-component information of each pixel is complete, is 8bit, and each pixel occupies 3 bytes.

As shown in the following figure:

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

The sampled code stream is: Y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 V3

The mapped pixel is: [Y0U0V0] [Y1U1V1] [Y2U2V2] [Y3U3V3]

You can see that this sampling method is the same as the size of the RGB image.

YUV 4:2:2

YUV 4:2:2 means that the sampling rate of the UV component is half that of the Y component.

As shown in the following figure:

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

The sampled code stream is: Y0U0Y1V1Y2U2Y3U3

The mapped pixels are: [Y0U0V1], [Y1U0V1], [Y2U2V3], [Y3U2V3]

Among them, for each pixel sampled, the Y component will be sampled, and the U and V components will be collected at intervals. When mapped to pixels, the first pixel and the second pixel share U0 and V1 components, and so on. Thus, the image space is saved.

For example, an image with a size of 1920 * 1280 will be sampled at 4:2:2 by YUV:

(1920 * 1280 * 8 + 1920 * 1280 * 0.5 * 8 * 2) / 8 / 1024 / 1024 = 4.68m

As you can see, it saves 1/3 of the storage space than RGB.

YUV 4:2:0

YUV 4:2:0 does not mean that the V component is not sampled. It means that for each scan line, only one chrominance component is stored at the sampling rate of 2:1, and the adjacent scan lines store different chrominance components. That is, if the first line is 4:2:0, the next line is 4:0:2, the next line is 4:2:0, and so on.

As shown in the following figure:

The image pixels are:

[Y0 U0 V0] 、 [Y1 U1 V1] 、 [Y2 U2 V2] 、 [Y3 U3 V3]

[Y5 U5 V5] 、 [Y6 U6 V6] 、 [Y7 U7 V7] 、 [Y8 U8 V8]

The sampled code stream is:

Y0 U0 Y1 Y2 U2 Y3

Y5 V5 Y6 Y7 V7 Y8

The mapped pixels are:

[Y0 U0 V5] 、 [Y1 U0 V5] 、 [Y2 U2 V7] 、 [Y3 U2 V7]

[Y5 U0 V5] 、 [Y6 U0 V5] 、 [Y7 U2 V7] 、 [Y8 U2 V7]

Among them, for each pixel sampled, the Y component is sampled, and the U and V components are sampled at 2:1 interlaced.

A 1920 * 1280 image, sampled at 4:2:0 by YUV, is:

(1920 * 1280 * 8 + 1920 * 1280 * 0.25 * 8 * 2) / 8 / 1024 / 1024 = 3.51m

Compared with RGB, it saves half the storage space.

YUV storage format

YUV data is stored in two formats: flat format (planar format) and packaged format (packed format).

Planar format: first stores the Y of all pixels sequentially, followed by the U of all pixels, followed by the V of all pixels.

Packed format: the Y, U, V of each pixel are continuously interlaced.

Because of different sampling methods and storage formats, there will be a variety of YUV storage methods. Here we only introduce the storage methods based on YUV422 and YUV420.

YUYV

YUYV format belongs to YUV422, which is stored in packaging format. Y and UV components are sampled according to 2:1 proportion. Each pixel collects Y component and every other pixel collects its UV component.

Y0 U0 Y1 V0 Y2 U2 Y3 V2

Y0 and Y1 share U0V0 component, Y2 and Y3 share U2V2 component.

UYVY

UYVY is also one of the storage formats for YUV422 samples, but in reverse order to YUYV.

U0 Y0 V0 Y1 U2 Y2 V2 Y3

YUV 422P

YUV422P is a kind of YUV422, which is a planer mode, that is, Y, U, V are stored respectively.

YUV420P and YUV420SP

YUV420P is based on the planar plane mode for storage, first storing all Y components, and then storing all U components or V components.

Similarly, YUV420SP is also based on planar plane mode storage, which is different from YUV420P in that its U and V components are stored in the alternating order of UV or VU.

YU12 and YU21

Both YU12 and YV12 formats belong to the YUV 420p type, that is, the Y component is first stored, and then the U and V components are stored. The difference is that YU12 is Y first and then U, while YV12 is Y then V first.

NV21 and NV21

Both NV12 and NV21 formats are of type YUV420SP. It also stores the Y component first, but then instead of storing all the U or V components, it stores the UV components alternately and continuously.

NV12 is a pattern in IOS, and its storage order is to store Y components first, and then UV to store them alternately.

NV21 is a mode in Android, which is stored in the first Y component and alternately in VU.

Conversion between YUV and RGB

The conversion between YUV and RGB is to convert the R, G, B components and Y, U, components of all the pixels of the image into each other.

There are the following conversion formulas:

The above is about the content of this article on "what are the advantages of YUV in android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report