经过了前面(1),(2)两个专题的学习,我们大概对视频压缩中的YCbCr颜色空间有了简单的了解。但是前面的都是理论的知识。

这里,我转载了一篇很浅显易懂的文章,利用了Matlab进行了实际仿真。帮助大家有个感性的认识。

文中,利用Matlab(可能需要Image Tool Box的支持),对利用RGB颜色空间保存的JPEG图片,进行了颜色空间的转换(rgb2ycbcr)分离(3个颜色通道),将实例图片的Y U V成分分别以灰度值彩色(将其他两个通道成分的成分置为0,然后用ycbcr2rgb进行逆转换)的形式表现了出来,比较直观。

文章的下半部分,则对学习专题(2)中的Sub-Sampling进行了进一步的阐释,有助于大家加深印象。

另外,如果没有正版的Matlab的话,可以尝试用开源的Octave进行尝试。

By RuanYuan.Net@admin  20120724


文章原来的地址 http://www.roman10.net/ycbcr-color-spacean-intro-and-its-applications/
------------------------------------------------------------------------------------

Color space is a complicated topic. Colors don’t really exist, like dust does. We human being use colors to describe what we see. The most common way to describe what we see in terms of color is using combination of red, green and blue, which is referred as RGB color space.

A color space is simply a model of representing what we see in tuples. YCbCr is one of the popular color space in computing. It represents colors in terms of one luminance component/luma (Y), and two chrominance components/chroma(Cb and Cr).

Terms

YUV, Y’UV, YCbCr, Y’CbCr, YPbPr… All these terms cause lots of confusion. YUV and Y’UV are traditionally for analog encoding of color information in television system, it uses different conversion constants from YCbCr; while YCbCr or Y’CbCr are used for digital encoding of color information in computing systems; and YPbPr is the analog counterpart of YCbCr. Nowadays, YUV is also used in the digital video context, in which case it is almost equivalent to YCbCr.

Here we negnect the terminologies and focuses on understanding the colorspace and its usage in the context of computing world. From this point onwards, we’ll call it YCbCr.

Why YCbCr Color Space?

Study shows human eyes are sensitive to luminance, but not so sensitive to chrominance. For example, given an image below,

Figure 1. A Color Image

One can use the matlab code below to display its Y, Cb, Cr component as color images or gray scale images.

%a program to display the image's ycbcr component
function [] = ycctest(imageName)
    rgb = imread(imageName);
    ycbcr = rgb2ycbcr(rgb);   %convert to yuv space
    %display the y component as a color image
    ycbcry = ycbcr;
    ycbcry(:,:,2) = 0;
    ycbcry(:,:,3) = 0;
    rgb1 = ycbcr2rgb(ycbcry);
    figure, imshow(rgb1);
    % display the cb component as a color image
    ycbcru = ycbcr;
    ycbcru(:,:,1) = 0;
    ycbcru(:,:,3) = 0;
    rgb2 = ycbcr2rgb(ycbcru);
    figure, imshow(rgb2);
    % display the cr component as a color image
    ycbcrv = ycbcr;
    ycbcrv(:,:,1) = 0;
    ycbcrv(:,:,2) = 0;
    rgb3 = ycbcr2rgb(ycbcrv);
    figure, imshow(rgb3);
    %display the y, cb, cr component as gray scale image
    figure,imshow(ycbcr(:,:,1));
    figure,imshow(ycbcr(:,:,2));
    figure,imshow(ycbcr(:,:,3));
end


Save the program as ycctest.m, and save the image as test.jpg. Then execute the program in matlab by typing command,

ycctest(‘./test.jpg’);

You’ll get the 3 color images for Y, Cb and Cr component from left to right as,

Figure 2. Color Images formed by Y, Cb and Cr Components

You’ll also get another 3 gray-scale images for Y, Cb and Cr component from left to right,

Figure 3. Gray-scale Images formed by Y, Cb and Cr Components

It’s not difficult to tell that our eyes perceive more info from the left most images in figure 2 and figure 3, which is formed by Y component of figure 1.

YCbCr color space makes use of this fact to achieve more efficient representation of scenes/images. It does so by separating the luminance and chrominance components of a scene, and use less bits for chrominance than luminance. The details of how to use less bits to represent chrominance is covered in Sub-sampling section below.

How does the Conversion Work?

The YCbCr image can converted to/from RGB image. There’re several standards defined for the conversion at different context. The conversion below is based on the conversion used in JPEG image compression.

The conversion can be expressed as equations below.

From 8-bit RGB to 8-bit YCbCr:

Y = 0.299R + 0.587G + 0.114B
Cb = 128 – 0.168736R – 0.331264G + 0.5B
Cr = 128 + 0.5R – 0.418688G – 0.081312B

From 8-bit YCbCr to 8-bit RGB:

R = Y + 1.402 (Cr – 128)
G = Y – 0.34414 (Cb – 128) – 0.71414(Cr – 128)
B = Y + 1.772 (Cb – 128)

Color Sub-sampling

The representation of YCbCr separates the luminance and chrominance, so the computing system can encode the image in a way that less bits are allocated for chrominance . This is done through color subsampling, which simply encodes chrominance components with lower resolution.

Here we cover four commonly used subsampling schemes: 4:4:4, 4:2:2, 4:2:0, and 4:1:1.

These four schemes are illustrated by the figure below [1],

Figure 4. Color Subsampling

The 4:4:4 is actually full resolution in both horizontal and vertical directions, there’s no subsampling done. 4:2:2 requires 1/2 resolution in horizontal direction; 4:1:1 requires 1/4 resolution in horizontal direction; and 4:2:0 means 1/2 resolution in both horizontal and vertical directions.

There’re also 4:4:0 and 4:1:0 schemes, interested readers could refer to reference 2.

Note that the sub-sampling process is lossy when comparing the processed image with the original image. The amount of info left can be calculated by summing up all components and divide by 12 (or 16, if alpha/transparency component exists). For the four subsampling schemes we mentioned, the amount of info left is 100%, 8/16=50%, 6/16 = 37.5%, 6/16 = 37.5%. In this way, the computing system could represent the image with less bits.

But how the image is reconstructed for display? Normally the image requires a Y, Cb, Cr component at every pixel. The reconstruction is done through interpolation or simply use the CbCr value of nearby pixel if the pixel doesn’t have CbCr values. The details are not covered in this post.

Applications

YCbCr is a commonly used color space in digital video domain. Because the representation makes it easy to get rid of some redundant color information, it is used in image and video compression standards like JPEG, MPEG1, MPEG2 and MPEG4.

References:

Basics of Video: http://lea.hamradio.si/~s51kq/V-BAS.HTM

Chrominance Subsampling: http://dougkerr.net/pumpkin/articles/Subsampling.pdf

JPEG File Interchange Format: http://www.w3.org/Graphics/JPEG/jfif3.pdf


共收到 2 条回复
acedemic · #2 · 2012-7-25 16:44:17  回复 支持 反对
我表示完全看不懂

点评

以后如果从事相关领域的研究,就不难~  详情 回复 发表于 2012-7-25 19:41
admin · #3 · 2012-7-25 19:41:43  回复 支持 反对
acedemic 发表于 2012-7-25 16:44
我表示完全看不懂

以后如果从事相关领域的研究,就不难~
回帖
B Color Image Link Quote Code Smilies
Command + Enter
快速回复 返回顶部 返回列表