色度二次抽樣

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個像素高的區域中的亮度和色度採樣值的數量。

  1. J:水平抽樣參考(概率區域的寬度)。通常是4
  2. a:J個像素的第一行中色度樣本(Cr,Cb)的數量
  3. b:J個像素的第一個行和第二行中的色度樣本(Cr,Cb)的變化次數。
  4. 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章