A text read rawRGB, RGB and YUV data format conversion

rawRGB     

        Image acquisition process is as follows: an object is imaged in reflected light -> Lens Aggregation -> the Sensor photoelectric conversion -> the ADC is converted to rawRGB

Since each pixel of the light intensity collected only on a particular color sensor, so each pixel sensor only R or G or B, and data formed became rawRGB data.

         rawRGB sensor output data directly after the photoelectric conversion of the ADC samples the data, the data is not processed, various represents the intensity of the received light sensor.

         For different sensor, rawRGB data format is formed in the interior thereof is also different. rawRGB four data arrangement format as follows (where the format for the 2 * 2 pixel matrix terms):

 

        Suppose a sensor 8 * 8 pixels (resolution of 8 * 8), then the sensor will have 8 * 8 photosites, each photosensitive point is a transistor. RawRGB then for 4 kinds of data in the table format as shown below:

        Can be seen from FIG, G component rawRGB data formats are each B, R component twice, because the human eye is more sensitive to green, so that the increase in weight of the weight of the photosensitive point, adds sampling the green information.

         For rawRGB sensor output data, need to be sent in the ISP (image signal processor) to give the RGB data, an interpolation process is generally employed. When the process is performed ISP, ISP needs to know the order of the size rawRGB sensor output data, wherein the sequence is generally achieved by the ISP registers the pattern, size is generally disposed in the ISP input format control register.

         Well, there's a problem: in rawRGB data, each pixel only R, G, B three-component color in a component, then this component a bit much to express it with? The answer in the following table:

        The reason why a data rawRGB this format, the aim is generally to reduce the physical process difficulty sensing device, and then restore a more realistic image information through the ISP process.

RGB

        In the digital era, the need for a standard to quantify the various colors of nature. RGB is a representation in the field of digital color standard, also referred to as one color space, by using three primary colors R, G, B luminance combinations of different values to a particular color to indicate that a. Note that, the RGB luminance value is kept inside the color, instead of chrominance values.

        In practical applications, RGB format there are many, the reason for the existence of these formats is that as technology advances, the change of the system, different scenarios and device environment, the demand for color expression is different.

        RGB format commonly used in the following table:

format

description

RGB565

1. Each pixel is represented by 16, the RGB components respectively with 5 bits, 6 bits, 5 bits.

2. The memory arrangement (high byte -> Low Byte): RRRRRGGGGGGBBBBB

RGB555

1. Each pixel is represented by 16-bit, RGB component 5 are used (without a rest)

2. The memory arrangement (high byte -> Low Byte): XRRRRGGGGGBBBBB (X indicates not to be ignored)

RGB24(RGB888)

1. Each pixel is represented by 24, RGB component of each 8-bit. Each component of RGB in memory in the order of: BGR BGR BGR ......

2. The memory arrangement (high byte -> Low Byte): BBBBBBBBGGGGGGGGRRRRR RRR

RGB32

1. Each pixel is represented by 32-bit, RGB component of each 8-bit (8 without remaining)

2. The memory arrangement (high byte -> Low Byte): BBBBBBBBGGGGGGGGRRRRR RRRXXXXXXXX (X indicates not to be ignored)

ARGB32

1. Each pixel is represented by 32-bit, RGB component of each 8-bit (8 bits for indicating the remaining Alpha channel value)

2. The memory arrangement (high byte -> Low Byte): BBBBBBBBGGGGGGGGRRRRR RRRAAAAAAAA

YUV

        YUV是一种色彩编码方法,Y表示亮度,U和V表示色度。只有Y就是黑白图像,再加上UV就是彩色图像了。YUV的一个好处就是让彩色系统和传统黑白系统很好的兼容,同时利用了人类视觉系统对亮度的敏感度比对色度高。

        在一般应用中,人们所说的YUV就是YCbCr,这我认为是从狭义的角度理解(毕竟现在是数字信号的天下,YCbCr恰好是描述数字信号的)。广义上说,YUV是一种色彩空间分类,一种颜色模型,具体的类型有Y'UV, YUV, YCbCr,YPbPr等,目前市场上常用数字的视频信号和视频/图片文件中的编码格式,用YCbCr来描述,于是人们口中的YUV就代指的是YCbCr,常见应用如H.264/H.265码流、MPEG、JPEG等。

        YCbCr中的Cb指蓝色色度分量,而Cr指红色色度分量。

        YUV和RGB的相同点:都是用来表达颜色的数学方法;

        YUV和RGB的相同点:对颜色的描述思路和方法不同。RGB将一个颜色拆解为3个纯色的亮度组合,YUV将一个颜色分解为一个亮度和2个色度的组合。

        那引入YUV这种色彩空间的好处具体有啥呢?

 1.   YUV提取Y亮度信号,可以直接给黑白电视使用,兼容黑白电视

 2.  人眼对UV的敏感性小于亮度,这样我们适当减少uv的量,而不影响人的感官。所以才会有多种格式的 YUV描述,如420、422、444。

3.  伴随显示设备分辨率的提升,bt组织也针对yuv2rgb设定了不同的系数,来最好的从YUV转换到RGB。

4.  YUV格式可以比RGB格式储存空间小。

        那RGB存在的作用是什么呢?

        目前人类发明的所有彩色的输入输出设备,本质上都只支持RGB数据。哪怕设备允许YUV的输入输出,那也是经过内部的数据转换而间接支持。

YUV采样

        主流采样方式有如下三种:

                   YUV 4:4:4 采样

                   YUV 4:2:2 采样

                   YUV 4:2:0 采样

        1.YUV 444 采样

        全采样,对每个像素点的的YUV分量都进行采样,这样的三个分量信息量完整。

        2. YUV 422 采样

        部分采样,可节省1/3存储空间和1/3的数据传输量。UV分量是Y分量采样的一半,Y分量和UV 分量按照2 : 1的比例采样。如果水平方向有10个像素点,那么采样了10个Y分量,而只采样了5个UV分量。其中,每采样过一个像素点,都会采样其Y分量,而U、V分量就会间隔一个采集一个。

        3.YUV 420 采样

        部分采样,可节省1/2存储空间和1/2的数据传输量。YUV 420采样,并不是指只采样U分量而不采样V分量。而是指,在每一行扫描时,只扫描一种色度分量(U或者V),和Y分量按照2 : 1的方式采样。比如,第一行扫描时,YU 按照 2 : 1的方式采样,那么第二行扫描时,YV分量按照 2:1的方式采样。对于每个色度分量来说,它的水平方向和竖直方向的采样和Y分量相比都是2:1 。

YUV存储格式

        YUV存储格式通常有两大类:打包(packed)格式和平面(planar)格式。前者将YUV分量存放在同一个数组中,通常是几个相邻的像素组成一个宏像素(macro-pixel);而后者使用三个数组分开放 YUV 三个分量,就像是一个三维平面一样。

YUV422 Planar (YUV422P,也称为I422格式)

        这里,Y\U\V数据是分开存放的,每两个水平Y采样点,有一个U和一个V采样点,如下图:

        也就是说,U0V0由Y0、Y1共用,这样整幅图像较RGB就减少了1/3的存储空间。

        YUV 422P 格式,又叫做 I422格式,采用的是平面格式进行存储,先存储所有的 Y 分量,再存储所有的 U 分量,再存储所有的 V 分量。

        假如一个8*2像素的图像的该格式的存储分布如下图:

YUV422 packed

        此格式有两种情况:分为YUYV格式和UYVY格式。

        YUYV格式

               YUYV 格式是采用打包格式进行存储的,指每个像素点都采用 Y 分量,但是每隔一个像素采样它的UV分量。

               假如一个8*2像素的图像的该格式的存储分布如下图:

        UYVY格式

                UYVY 格式也是采用打包格式进行存储,它的顺序和YUYV相反,先采用U分量再采样Y分量。

                假如一个8*2像素的图像的该格式的存储分布如下图:

YUV420 Planar (YUV420P)

        这个格式跟YUV422 Planar 类似,但对于U和V的采样在水平和垂直方向都减少为2:1,根据采样规则如下图:

        也就是说,U0V0由Y0、Y1、YW、YW+1共用,这样整幅图像较RGB就减少了1/2的存储空间。

        YU12和YV12格式都属于YUV 420P类型,即先存储Y分量,再存储U、V 分量,区别在于:YU12是先Y再U后V,而YV12是先Y再V后U 。

        YU12格式(也称为I420格式)

                YU12是先Y再U后V。

                假如一个8*2像素的图像的该格式的存储分布如下图:

        YV12格式

                YV12是先Y再V后U

                假如一个8*2像素的图像的该格式的存储分布如下图:

YUV422 Semi-Planar (YUV422SP)

        Semi 是“半”的意思,个人理解这个是半平面模式,这个格式的数据量跟YUV422 Planar的一样,但是U、V是交叉存放的。                                              

        假如一个8*2像素的图像的该格式的存储分布如下图:

YUV420 Semi-Planar (YUV420SP)

        这个格式的数据量跟YUV420 Planar的一样,但是U、V是交叉存放的。

        NV12和NV21格式都属于 YUV420SP 类型。它也是先存储了Y分量,但接下来并不是再存储所有的U或者V分量,而是把UV分量交替连续存储。

        NV12

                NV12是IOS中有的模式,它的存储顺序是先存Y分量,再UV进行交替存储。

                假如一个8*2像素的图像的该格式的存储分布如下图:

        NV21

                NV21是安卓中有的模式,它的存储顺序是先存Y分量,在VU交替存储。

                假如一个8*2像素的图像的该格式的存储分布如下图:

RGB与YUV转换

        由于YUV有这数字信号和模拟信号的YUV类型,于是RGB与YUV转换方式多种多样,大致分为模拟和数字两种。每种方式下,不同的清晰度视频信号的转换公式也是有所不同。

        这里只讨论了数字信号的转换,数字RGB转YUV的推导公式为:

                Wr + Wg + Wb = 1; Umax = Vmax = 0.5;                       (1)

                Y = 16 + 219 * (Wr * R + Wg * G + Wb * B) / 255;              (2)

                Cb = U = 128 + 224 * (Umax * (B - Y) / (1 - Wb)) / 255;         (3)

                Cr = V = 128 + 224 * (Vmax * (R - Y) / (1 - Wr)) / 255;        (4)

        注意:(1)(2)(3)(4)公式中WrWgWb  的值如下表所示:

清晰度 Wr Wg Wb
BT601(标清国际定义) 0.299 0.587 0.114
BT709(高清) 0.2126 0.7152 0.0722
BT2020(超清) 0.2627 0.678 0.0593

这里仅仅列出数字YUV(YCbCr)与数字RGB相互转换的BT601(标清国际定义)的转换公式:

         Y = 16 + 0.257 * R + 0.504 * g + 0.098 * b

        Cr = V = 128 + 0.439 * R - 0.368 * g - 0.071 * b

        Cb = U = 128 - 0.148 * R - 0.291 * g + 0.439 * b

 

        B = 1.164 *(Y - 16) + 2.016 *(Cb - 128)

        G = 1.164 *(Y - 16) - 0.392 *(Cb - 128) - 0.812 *(Cr - 128)

        R = 1.164 *(Y - 16) + 1.596 *(Cr - 128)

 

发布了1 篇原创文章 · 获赞 0 · 访问量 23

Guess you like

Origin blog.csdn.net/qq_29575685/article/details/103954096