当前位置:网站首页>YUV format and RGB format
YUV format and RGB format
2022-06-09 22:32:00 【StephenBarrnet】
YUV And RGB Format Introduction
One 、RGB Coding format
RGB The image has three channels R、G、B, Corresponding to red 、 green 、 Three components of blue , The color is determined by the values of the three components ; Usually , Will give RGB Image plus a channel alpha, Transparency , So there are four components to control the color .
In general ,RGB Image , Every pixel has red 、 green 、 Blue three primary colors , Each primary color takes up 8 bit, That's one byte , So a pixel is occupied 24 bit, That 's three bytes . If it is argb Format image ,1 Pixels required 32 bit, That is to say 4 Bytes .
In the image display , a sheet 1280 * 720 Size picture , It means it has 1280 * 720 Pixels . The color of each pixel is displayed in RGB coding method . a sheet 1280 * 720 Size picture , Take up 1280 * 720 * 3 / 1024 / 1024 = 2.63 MB Storage space .
Two 、YUV Coding format
YUV Compared with RGB The biggest advantage of the format is that it can achieve without obvious reduction of image quality , Reduce file size .TUV The reason why format can do , Because of the sampling operation .
YUV Color coding uses Brightness and chroma To specify the color of the pixel .. among ,Y Express Brightness (Luminance、Luma), and U and V Express chroma (Chrominance、Chroma).
and RGB Indicates that the image is similar to , Every pixel contains Y、U、V component . But it's Y and UV Components can be separated , without UV The component can also display the complete image , It's just black and white .
about YUV Image , Not every pixel needs to contain Y、U、V The three components , According to different sampling formats , Can each Y Each component corresponds to its own UV component , Or a few Y Share the weight UV component .

YUV Storage format ( classification ):
YUV Two major categories of formats : Plane (plannr) and compact (packed).
- about planar Of YUV Format , First, store all pixels in a row Y, And then it stores all the pixels U, Along with the storage of all pixels V, Or first v after u
- about packed Of YUV Format , Every pixel point Y,U,V It's a continuous alternate storage . such as YUV420P, among P It means compact ,YUV420SP Among them SP Express “ Semi compact ”.
YUV420P:YYYYYYYY UU VV
YUV420: YUV YUV YUV
- packed:Y、U、V The components are interspersed , There is one of the three components Byte Type array ;
- planar:Y、U、V There are three components Byte Type array .
YUV Sampling methods :
YUV There are three main ways of sampling ,YUV4:4:4,YUV4:2:2 ,YVU4:2:0.
- YUV 4:4:4 sampling :YUV 4:4:4 sampling , signify Y、U、V The sampling scale of the three components is the same , So in the resulting image , The three components of each pixel are complete , All are 8 bit, That's one byte .
As shown in the figure below :
among ,Y The component is represented by a cross ,UV The component is represented by a circle .
for instance :
If the image pixel is :[Y0 U0 V0]、[Y1 U1 V1]、[Y2 U2 V2]、[Y3 U3 V3]
Then the sampled code stream is :Y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 V3
Finally, the mapped pixels are still [Y0 U0 V0]、[Y1 U1 V1]、[Y2 U2 V2]、[Y3 U3 V3]
You can see the images and RGB The image size of the color model is the same , Did not achieve the purpose of saving bandwidth , When will RGB Image to YUV In the picture , It's also a conversion to YUV 4:4:4 Sampled images .
- YUV4:2:2 sampling :YUV 4:2:2 sampling , signify UV The weight is Y Half of the component sampling ,Y Weight and UV Component according to 2 : 1 Proportional sampling . If there is... In the horizontal direction 10 Pixels , So sampling 10 individual Y component , And only sampled 5 individual UV component .
As shown in the figure below :
among ,Y The component is represented by a cross ,UV The component is represented by a circle .
for instance :
If the image pixel is :[Y0 U0 V0]、[Y1 U1 V1]、[Y2 U2 V2]、[Y3 U3 V3]
Then the sampled code stream is :Y0 U0 Y1 V1 Y2 U2 Y3 V3
among , Every pixel sampled , Will sample its Y component , and U、V Components will be collected one at a time .
Finally, the mapped pixels are [Y0 U0 V1]、[Y1 U0 V1]、[Y2 U2 V3]、[Y3 U2 V3]
The sampled code stream is mapped to pixels , It is still necessary to meet that each pixel has Y、U、V The three components . But you can see , The first and second pixels are in common U0、V1 component , The third and fourth pixels are common U2、V3 component , This saves image space .
a sheet 1280 * 720 Size picture , stay YUV 4:2:2 The sample size is :
(1280 * 720 * 8 + 1280 * 720 * 0.5 * 8 * 2)/ 8 / 1024 / 1024 = 1.76 MB
You can see YUV 4:2:2 The sampled image is better than RGB The model image saves one third of the storage space , The bandwidth occupied during transmission will also be reduced .
- YUV 4:2:0 sampling :YUV 4:2:0 sampling , It's not just sampling U Component without sampling V component . But to , At each line scan , Scan only one chrominance component (U perhaps V), and Y Component according to 2 : 1 The way of sampling . such as , When the first line is scanned ,YU according to 2 : 1 The way of sampling , So when the second line is scanned ,YV Component according to 2:1 The way of sampling . For each chroma component , Its horizontal and vertical sampling and Y The components are all 2:1 .
As shown in the figure below :
among ,Y The component is represented by a cross ,UV The component is represented by a circle .
Suppose the first line is scanned U component , The second line scans V component , Then you need to scan two lines to form a complete UV component .
for instance :
Suppose the image pixel is :
[Y0 U0 V0]、[Y1 U1 V1]、 [Y2 U2 V2]、 [Y3 U3 V3]
[Y5 U5 V5]、[Y6 U6 V6]、 [Y7 U7 V7] 、[Y8 U8 V8]
Then the sampled code stream is :Y0 U0 Y1 Y2 U2 Y3 Y5 V5 Y6 Y7 V7 Y8
among , Every pixel sampled , Will sample its Y component , and U、V The components are separated by a line according to 2 : 1 sampling .
Finally, 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]
From the mapped pixels, you can see , four Y The components share a set UV component , And according to 2*2 Distributed in the form of a small square , comparison YUV 4:2:2 Two of the samples Y Components share one set UV component , This will save more space .
a sheet 1280 * 720 Size picture , stay YUV 4:2:0 The sample size is :
(1280 * 720 * 8 + 1280 * 720 * 0.25 * 8 * 2)/ 8 / 1024 / 1024 = 1.32 MB
You can see YUV 4:2:0 The sampled image is better than RGB Model images save half of the storage space , Therefore, it is also a mainstream sampling method .
common YUV Format
- YUV422:YUYV、YVYU、UYVY、VYUY
Each of these four formats can be divided into 2 class (packed and planar), With YUYV For example , One 6*4 The image of is stored as follows :
Y Y Y Y Y Y
Y Y Y Y Y Y
Y Y Y Y Y Y
Y Y Y Y Y Y
U U U U U U Y U Y V Y U Y V Y U Y V
U U U U U U Y U Y V Y U Y V Y U Y V
V V V V V V Y U Y V Y U Y V Y U Y V
V V V V V V Y U Y V Y U Y V Y U Y V
- Planar - - Packed -
- YUV420:I420、YV12、NV12、NV21
YUV420p: I420、YV12
YUV420sp: NV12、NV21
Again , For one 6*4 Image , The four pixel formats are stored as follows :
Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
U U U U U U V V V V V V U V U V U V V U V U V U
V V V V V V U U U U U U U V U V U V V U V U V U
- I420 - - YV12 - - NV12 - - NV21 -
- I420、YV12 All three components are in plane format , That is, there are three Byte Type array ;
- NV12、NV21 The storage format of is Y Plane ,UV pack , namely Y Information is stored in an array ,UV Information is stored in a matrix .
3、 ... and 、RGB And YUV Conversion formula
YUV The pixel format comes from RGB Pixel format , Through formula operation ,YUV Three components can be reduced to RGB,YUV turn RGB The formula is as follows :
R = Y + 1.403V
G = Y - 0.344U - 0.714V
B = Y + 1.770U
commonly , take RGB and YUV The scope of is limited to [0,255] between , Then there is the following conversion formula :
R = Y + 1.403(V - 128)
G = Y - 0.344(U - 128) - 0.714(V - 128)
B = Y + 1.770(U - 128)
References:
Common image pixel formats NV12、NV2、I420、YV12、YUYV
Article to read YUV Sampling and format of
边栏推荐
- 【BP预测】基于Adaboost的BP神经网络实现数据回归预测附matlab代码
- [the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
- 「ClickHouse系列」ClickHouse的优化之Block+LSM
- 建筑工地数字化监管和科学战疫的智慧力量
- The little schemer Chinese version
- Find my product | the new TWS headset supports the find my function, and apple find my is more widely used in third-party manufacturers
- RCNN series summary
- Aquanee will land in gate and bitmart in the near future, providing a good opportunity for low-level layout
- Re summary of mongodb installation, configuration, error handling, crud operation, etc
- June training (day 09) - two point search
猜你喜欢

10个常见触发IO瓶颈的高频业务场景
![[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language](/img/53/d6f05e8050e27dc9d59f1196753512.png)
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language

Pi of C language test question 162

这本书押中了2022北京高考作文题

稍微复杂的查询

Know how to pay attention to the hot 25K problem, self-study software testing, and how much you need to learn to find a job?

10 common high-frequency business scenarios that trigger IO bottlenecks

2022安全生产月活动启动安全生产与疫情防控两手抓

Rotation of AVL tree

Find My技术|物联网时代,苹果Find My实现真正的智能防丢
随机推荐
Bonner visual lens lcf08lk1f
Début de la production de sécurité et prévention et contrôle des épidémies
C语言试题168之获取矩阵的最大值及其下标
【翻译论文】A Progressive Morphological Filter for Removing Nonground Measurements From Airborne LIDAR Dat
Cookies and session workflows
On a machine with 4GB of physical memory, how about applying for 8g of memory?
Solving definite integral of C language test question 164
Que se passe - t - il si vous appliquez 8G sur une machine avec 4go de mémoire physique?
Intelligent prevention and control of safety production risk at construction site in flood season
[BP prediction] BP neural network based on AdaBoost realizes data regression prediction with matlab code
Learn how to parse SQL from kernel code
SDN specific network security issues
All inherited features
【BP预测】基于Adaboost的BP神经网络实现数据回归预测附matlab代码
Matrix transpose of C language test question 170
Lidar related introduction
设计备忘录解矩阵链(动态规划法)的一些思考
2022 safety production month activity starts safety production and epidemic prevention and control
[image encryption and decryption] image encryption and decryption based on chaotic sequence combined with dwt+svd (including correlation test) including Matlab source code
Technology sharing behind NFT and opensea transactions