1.Cemera原理简介
我们先了解相机的原理。
景物经过镜头聚焦投射到Sensor上,期间会经过Bayer filter的处理:
Bayer filter确保每次仅有一种颜色被存储,因此每个小单元格里只有一种颜色(红色或绿色或蓝色)。也就是说,原始Raw Data是不完全的像素集合。
我们要通过“反马赛克”过程,把单个像素(红色或绿色或蓝色)变换为全色像素(RGB)。
然后进行RGB转YCrCb,之后会对YCrCb进行色度二次采样,目的是压缩图片/视频大小。
从Raw Data到色度二次采样的流程如下图所示:
备注: (1)YCbCr或Y'CbCr有的时候会被写作:YCBCR或是Y'CBCR,是色彩空间的一种,通常会用于影片中的影像连续处理,或是数字摄影系统中。Y'为颜色的亮度(luma)成分、而CB和CR则为蓝色和红色的浓度偏移量成份。 (2)术语Y'UV,YUV,YCbCr,YPbPr等的范围有时是不明确的和重叠的。 历史上,术语YUV和Y'UV用于电视系统中的颜色信息的特定模拟编码,而YCbCr用于适合于视频和静止图像压缩和传输(例如MPEG和JPEG)的颜色信息的数字编码。 今天,术语YUV通常在计算机工业中用于描述使用YCbCr编码的文件格式。 |
2.色度子采样(Chroma subsampling)
色度子采样是通过实现针对色度信息比亮度信息更少的分辨率来编码图像的做法,利用人类视觉系统对于色差比亮度更低的敏感度。它用于许多视频编码方案——模拟和数字——以及JPEG编码。
色度子采样的目的是:降低存储彩色图像所用的比特数,从而实现图像或视频的压缩。
子采用方案通常表示为三部分比例J:a:b(例如:4:2:2)或四个部分(如果存在alpha通道(例如:4:2:2:4)),它描述了在J个像素宽,2个像素高的区域中的亮度和色度采样值的数量。
- J:水平抽样参考(概率区域的宽度)。通常是4
- a:J个像素的第一行中色度样本(Cr,Cb)的数量
- b:J个像素的第一个行和第二行中的色度样本(Cr,Cb)的变化次数。
- Alpha:水平因子(相对于第一个数字)。如果不存在alpha分量,可以省略,当存在时等于J。
备注:维基百科的“J:a:b”概念和另外一种概念“Y:Cb:Cr”是不一样的。
“4:2:0”比较特殊。
In 4:2:0, the horizontal sampling is doubled compared to 4:1:1, but as the Cb and Cr channels are only sampled on each alternate line in this scheme, the vertical resolution is halved. The data rate is thus the same. This fits reasonably well with the PAL color encoding system since this has only half the vertical chrominance resolution of NTSC. It would also fit extremely well with the SECAM color encoding system since like that format, 4:2:0 only stores and transmits one color channel per line (the other channel being recovered from the previous line). However, little equipment has actually been produced that outputs a SECAM analogue video signal. In general SECAM territories either have to use a PAL
3.参考文章一
维基百科的解读,尽管非常经典,也很本质,但是过于抽象,难以理解。
有一篇博客文章,更容易理解“J:a:b”这个概念。
文章地址:
https://calendar.perfplanet.com/2015/why-arent-your-images-using-chroma-subsampling/
《Why aren’t your Images using Chroma-Subsampling?》非常棒的一篇。
其中有一段话:
You can read it like this: Given 4 pixels wide (J), how many unique unique color-pixels in row 1, and row 2 should be used. In this way:
4:4:4 use 4 unique pixels on the first row, and 4 unique on the second.
4:2:0 means use 2 unique pixels (every other entry) and use the same value on the second row as below
上面的图片能帮助我们更好的理解“J:a:b”概念。
4.参考文章二
上面仍然只是原理,而且也是模型,离我们的主观理解还有距离。下面,我们看看更容易理解的解释。
《Color Subsampling, or What is 4:4:4 or 4:2:2?》
4:4:4 4:2:2 4:1:1 4:2:0
This diagram shows one of many ways that 4:2:0 color subsampling can be accomplished, but the general idea is the same – Luma samples for each pixel, one line has Cb samples for every other pixel, and the next line has Cr samples for every other pixel.
5.参考文章三
4:1:1格式在每一个有效行内,都有亮度值4个,色差样值Cr和Cb各1个(总计1x2=2)。
4:2:0格式在每一个有效行内,除了亮度值4个外,只有色差样值Cr或Cb其中的一种2个出现,在相邻的有效行之间Cr、Cb交替出现。注意:“4:2:0”中的0,它表示的是两种色差样值在传送时是每行交替进行的,而绝不是有一个色差信号不取样。
6.参考文章四
我们再来看一篇文章。
文章网址:http://encyclopedia2.thefreedictionary.com/chroma+subsampling
YCbCr Is Designated as 4:n:n (Y:Cb:Cr)
The 4 is the sampling rate of the luma, and n:n represents Cb:Cr. Review the illustrations below. Each 8x8 matrix represents a "macroblock" of 64 pixels in a video frame. The pink squares are the pixel locations where the sample is taken.
备注:这篇文章中定义的“Y:Cb:Cr”描述概念和维基百科“J:a:b”不一样。难道行业内有两种不同的描述吗?作者的图画得很好,能帮助我们理解。
参考:
1.《H.264和MPEG-4视频压缩:新一代多媒体的视频编码技术》。
2.《新一代视频压缩编码标准H.264》
3. https://en.wikipedia.org/wiki/YCbCr
4. https://en.wikipedia.org/wiki/YUV
5. https://en.wikipedia.org/wiki/Chroma_subsampling