1. 程式人生 > >OPENCV學習筆記3-7_RGB->YCbCr

OPENCV學習筆記3-7_RGB->YCbCr

digital tor oot ssi ice buffer ica 方案 空間

色彩空間用數學方式來描述顏色集合,常見的2個基本色彩模型是RGB,YUB.

? RGB - Used in computer graphics

? YCbCr - Used in video compression

1.1 YCbCr

YCbCr 則是在世界數字組織視頻標準研制過程中作為ITU - R BT.601 建議的一部分,其實是YUV經過縮放和偏移的翻版。其中Y與YUV 中的Y含義一致,Cb,Cr 同樣都指色彩,只是在表示方法上不同而已。YCbCr或Y‘CbCr色彩空間通常會用於影片中的影像連續處理,或是數字攝影系統中,其中Y是指亮度(luma)分量(灰階值),Cb指藍色色度分量,而Cr指紅色色度分量。

醫學研究證明,人的肉眼對視頻的Y分量更敏感,因此在通過對色度分量進行子采樣來減少色度分量後,肉眼將察覺不到的圖像質量的變化。如果只有Y信號分量而沒有U、V分量,那麽這樣表示的圖像就是黑白灰度圖像。彩色電視采用YUV空間正是為了用亮度信號Y解決彩色電視機與黑白電視機的兼容問題,使黑白電視機也能接收彩色電視信號。

技術分享

RGB is not very efficient (有效)in terms of(就......而言) bandwidth(帶寬) as (因為)all the three components have to be present in equal bandwidth to produce(produce) any color. So an RGB based frame buffer(幀緩沖器) must have same pixel depth(像素深度) and display resolution for each RGB component.

YCbCr easy to get rid of(擺脫) some redundant color information(冗余的顏色信息), it is used in image and video compression standards like JPEG, MPEG1, MPEG2 and MPEG4.

YCbCr主要的子采樣格式有 YCbCr 4:2:0、YCbCr 4:2:2 和 YCbCr 4:4:4。

  • 4:4:4 – In this, there is no sub-sampling of the chroma components(色度分量的子采樣), and can be as well referred and used(被引用和使用) directly as a RGB image. High-end cameras devices use this format to not lose any data.
  • 4:2:2 – The chroma components(色度分量) are horizontally sub-sampled (被水平次采樣) and their resolution (解析度,分辨率)is halved (減半)as compared to(與x相比) the luminance counterpart (亮度對應)in this scheme(該方案). High-end digital video formats and still images(靜態圖像)generally employ(采用,employment 雇傭)this scheme.
  • 4:2:0 – In this variant(變種), the chroma components are sub-sampled by a factor of 2, both horizontally as well as vertically(水平方向和垂直方向), thus (因此)reducing to a factor (因子)of a quarter(1/4). The standard video compression MPEG uses this scheme。

1.2 YCbCr - RGB Color Format Conversion

For standard definition TV applications (SDTV) the following equation describes the color conversion from RGB to YCbCr (according to ITU-R BT.601):

技術分享

To recover an RGB color from a YCbCr color, the following inverse matrix is used:

技術分享

The possible range(可能範圍) of values for chrominance and luminance(色度和亮度值) reserves(保留) some footroom and headroom(空間和余量), which is necessary to provide some space for overshooting(過沖), e.g.( 例如) in combination with(結合) analog video equipment. In many cases the complete possible range (完整可能範圍)of 8 bit is used, this full-range color format is used for JPEG images.

The conversion of RGB colors into full-range YCbCr colors is described by the following equation(8-bit RGB to 8-bit YCbCr):

技術分享

These equations can be implemented in fixed-point arithmetic as follows:

y = (77 × r + 150 × g + 29 × b)/256

cb = (-43 × r - 85 × g + 128 × b + 32768)/256

cr = (128 × r - 107 × g - 21 × b + 32768)/256

The other way round(另一方面), to convert a full-range YCbCr color into RGB is described by the following equation:

技術分享

For high definition TV (HDTV), different coefficients(系數) are used. The possible range of values is identical to the SDTV, to provide the necessary footroom and headroom.

The following equation describes the color conversion from RGB to YCbCr for HDTV (according to ITU-R BT.709):

技術分享

This is the corresponding inverse matrix to get the RGB color components out of a YCbCr color:

技術分享

技術分享

OPENCV學習筆記3-7_RGB->YCbCr