算法-优化(rgb2yuv)

RGB

RGB色彩模式是工业界的一种颜色标准,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及他们互相之间的叠加来得到格式各样的颜色的,RGB是代表红、绿、蓝三个通道的颜色。

   RGB色彩模式使用RGB模型为图像中每一个像素的RGB分量分配一个0~255范围内的强度值。RGB图像只使用三种颜色,就可以使他们按照不同的比例混合,在屏幕上重现16777216(256*256*256)中颜色。

RGB color model

The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of teh three additive primary colors, red, green, and blue.

The main purpose of the RGB color model is for the sensing, representation, and display of images in electronic systems, such as televisions and computers, though it has also been used in conventional photography. Before the electronic age, the RGB color model already had a solid theory behind it, based in human perception of colors.

RGB is a device-dependent color model: different devices detect or reproduce a given RGB value differently, since the color elements (such as phosphors or dyes) and their response to individual R, G, and B levels vary from manufacturer to manufacturer, or even in the same device over time. Thus an RGB value does not define the same color across devices without some kind of color management.

Typical RGB input devices are color TV and video cameras, image scanners, and digital cameras. Typical RGB output devices are TV sets of various technologies (CRT, LCD, plasma, etc.), computer and mobile phone displays, video projectors, multicolor LED displays, and large screens such as JumboTron. Color printers on the other hand, are not RGB devices, but subtractive color devices (typically CMYK color model).


Additive primary colors

To form a color with RGB, three colored light beams (one red, one green, and one blue) must be superimposed (for example by emission from a black screen, or by reflection from a white screen).The RGB color model is additive in the sense that teh three light beams are added together, and their light spectra add, wavelength for wavelength, to make the final color's spectrum.


RGB and displays

One common application of the RGB color model is the diaplay of colors on a cathode ray tube (CRT),liquid crystal display (LCD), plasma display, or organic light emitting diode (OLED) display such as a television, a computer's monitor, or a large scale screen.


YUV

YUV是被欧洲电视系统所采用的一种颜色编码方法(属于PAL),是PAL和SECAM模拟彩色电视制式采用的颜色空间。在现代彩色电视系统中,通常采用三管彩色摄影机或彩色CCD摄影机进行取像,然后把取得的彩色图像信号经分色、分别放大校正后得到RGB,再经过矩阵变换电路得到亮度信号Y和两个色差信号R-Y(即U)、B-Y(即V),最后发送端将亮度和色差三个信号分别进行编码,用同一信道发送出去。这种色彩的表示方法就是所谓的YUV色彩空间表示。采用YUV色彩空间的重要性是它的亮度信号Y和色度信号U、V是分离的。

总结

YUV主要用于优化彩色视频信号的传输,使其向后相容老式黑白电视。与RGB视频信号传输相比,它最大的优点在于只需占用极少的频宽(RGB要求三个独立的视频信号同时传输)。其中"Y"表示明亮度(Luminance或Luma),也就是灰阶值;而"U"和"V"表示的则是色度(Chrominance或Chroma),作用是描述影像色彩及饱和度,用于指定像素的颜色。

YUV is a color space typically used as part of a color image pipeline. It encodes a color image or video taking human perception into account, allowing reduced bandwidth for chrominance components, thereby typically enabling transmission error or compression artifacts to be more efficiently masked by the human perception than using a "direct" RGB-representation. Other color spaces have similar properties, and the main reason to implement or investigate properties of Y'UV would be for interfacing with analog or digital television or photographic equipment that conforms to certain Y'UV standards.

The scope of the the terms Y'UV, YUV, YCbCr, YPbPr, etc, is sometimes ambiguous and overlapping. Historically, the terms YUV and Y'UV were used for a specific analog encoding of color information in television systems, while YCbCr was used for digital encoding of color information suited for video and still-image compression and transmission such MPEG and JPEG. Today, the term YUV is commonly used in the computer industry to describe file-formats that are encoded using YCbCr.

The Y'UV model defines a color space in terms of one luma(Y') and two chrominance (UV) components.


YUV&RGB来源上的差异

YUV色彩模型来源于RGB模型,给模型的特点是将亮度和色度分离开,从而适合于图像处理领域。

应用: basic color model used in analogue color TV broadcasting.用在模拟彩色电视广播的基本颜色模型中。

YCbCr模型来源于YUV模型。YCbCr is a scaled and offset version of the YUV color space.

应用:数字视频,ITU-R BT.601 recommendation

注意: 我们再H.264, MPEG等编码标准中用的YUV,其实是YCbCr,不要被名称搞混淆了。还有Y' 带有一撇,表示该符号在原来值得基础上进行了Gamma Correction.


YCbCr采样格式

4:4:4 采样就是说三个元素Y, Cb, Cr有同样的分辨率,这样的话,在每一个像素点谁跟你都对这三中元素进行采样。数字4是指,在水平方向上,对各种元素的采样率。比如说,每四个亮度采样点都有四个Cb的Cr采样值。4:4:4采样完整地保留了所有的信息值。

4:4:4采样,一共要进行12次采样,对每一个Y, Cb和Cr,就需要12*8=96位。

4:2:2采样中(有时候记为YUY2),色度元素在纵向与亮度值有同样的分辨率,而在横向则是亮度分辨率的一半(4:2:2表示每四个亮度值就有两个Cb和Cr采样。) 4:2:2视频用来构造高品质的视频彩色信号。

4:2:2采样有时候,被描述是一个“每个像素12位”的方法。这么说的原因可以从对四个像素的采样中看出。4:2:0就需要6*8=48位,平均每个像素48/4=12位。

4:2:0在这个流星的采样格式中(常记为YV12)Cb和Cr在水平和垂直方向上有Y分辨率的一半。4:2:0有些不同,因为它并不是指在实际采样中使用,而是在编码史中定义这种编码方法是用来区别于4:4:4和4:2:2方法的。4:2:0采样被广泛地应用于消费应用中,比如视频会议,数字电视和DVD存储中。因为每个颜色差别元素中包含了四分之一的Y采样元素量,那么4:2:0 YCbCr视频需要刚好4:4:4或RGB视频中采样量的一半。

4:2:0隔行扫描的视频序列中,对应于一个完整的视屏帧的Y, Cb, Cr 采样分配到两个场中。可以得到,各行扫描的总采样数跟渐进式扫描中使用的采样数目是相同的。


视频格式

实际中,捕捉或转化一个中间格式或一系列中间格式是很平常的事情。

CIF是一种常见的流行格式,并由它衍生出了4CIF和Sub-QCIF。帧分辨率的选取取决于应用程序,可使用的存储量以及传输带宽。比如说4CIF对于标准定义的电视和DVD视频来说是合适的,CIF和QCIF在视频会议中是常备使用的格式。QCIF和SQCIF对于移动设备的多媒体程序来说是合适的,在这种情况下,现实分辨率和码率都是有限的。以下是各种格式的具体使用位数的需求(使用4:2:0采样,对于每个元素用8个位大小表示)。

格式: Sub-QCIF    亮度分辨率:128*96    每帧使用的位:147456

格式: QCIF            亮度分辨率:176*144    每帧使用的位:304128

格式: CIF                    亮度分辨率:352*288    每帧使用的位:1216512

格式: 4CIF            亮度分辨率:704*576    每帧使用的位:4866048


速度取决于算法

同样的事情,方法不同,效果也就不一样。

代码的速度取决于以下几个方面

1.算法本身的复杂度,比如MPEG比JPEG复杂,JPEG比BMP图片的编码复杂。

2.CPU自身的速度和设计架构。

3.CPU的总线带宽。

4.自己代码的写法。(此项的可操作性很大)

探讨问题内容:

RGB格式的彩色图像转换为黑白图像。

转换公式如下:

Y = 0.299 * R + 0.587 * G + 0.114 * B;

图像尺寸

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值