Converting Between YUV and RGB

简介:

It is frequently necessary to convert between YUV pixel formats (used by the JPEG and MPEG compression methods) and RGB format (used by many hardware manufacturers.) The following formulas show how to compute a pixel's value in one format from the pixel value in the other format.

YUV format allows for higher compression rates without a proportionately high loss of data, as the U and V portions can be highly compressed and computed from the non- or lowly-compressed Y portion.

Computer RGB888, or full-scale RGB, uses 8 bits each for the red, green, and blue channels. Black is represented by R = G = B = 0, and white is represented by R = G = B = 255. The 4:4:4 YUV format uses 8 bits each for the Y, U, and V channels.

Converting RGB888 to YUV

The following formulas define the conversion from RGB to YUV:

Y = ( (  66 * R + 129 * G +  25 * B + 128) >> 8) +  16
U = ( ( -38 * R -  74 * G + 112 * B + 128) >> 8) + 128
V = ( ( 112 * R -  94 * G -  18 * B + 128) >> 8) + 128

These formulas produce 8-bit results using coefficients that require no more than 8 bits of (unsigned) precision. Intermediate results require up to 16 bits of precision.

Converting 8-bit YUV to RGB888

The following coefficients are used in conversion process:

C = Y - 16
D = U - 128
E = V - 128

Using the previous coefficients and noting that clip() denotes clipping a value to the range of 0 to 255, the following formulas provide the conversion from YUV to RGB:

R = clip(( 298 * C           + 409 * E + 128) >> 8)
G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
B = clip(( 298 * C + 516 * D           + 128) >> 8)

These formulas use some coefficients that require more than 8 bits of precision to produce each 8-bit result, and intermediate results require more than 16 bits of precision.

Note   All units range from 0 (zero) to 1.0 (one). In DirectDraw, they range from 0 to 255. Overflow and underflow can (and does) occur, and the results must be saturated.

To convert 4:2:0 or 4:2:2 YUV to RGB, convert the YUV data to 4:4:4 YUV, and then convert from 4:4:4 YUV to RGB.


 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.

目录
相关文章
|
XML 存储 开发工具
|
8月前
|
机器学习/深度学习 编解码 自然语言处理
SigLIP 2:多语言语义理解、定位和密集特征的视觉语言编码器
SigLIP 2 是一种改进的多语言视觉-语言编码器系列,通过字幕预训练、自监督学习和在线数据管理优化性能。它在零样本分类、图像-文本检索及视觉表示提取中表现卓越,支持多分辨率处理并保持图像纵横比。模型提供 ViT-B 至 g 四种规格,采用 WebLI 数据集训练,结合 Sigmoid 损失与自蒸馏等技术提升效果。实验表明,SigLIP 2 在密集预测、定位任务及多模态应用中显著优于前代和其他基线模型。
694 9
SigLIP 2:多语言语义理解、定位和密集特征的视觉语言编码器
|
人工智能 IDE 程序员
通义灵码:AI 研发趋势与效果提升实践丨SDCon 全球软件技术大会演讲全文整理
SDCon 全球软件技术大会上,阿里云通义灵码团队分享了关于 AI 辅助编码的最新研究与实践,随着 AIGC 技术的发展,软件研发领域将迎来智能化的新高度,助力 DevOps 流程优化,提升研发效率和研发幸福感。
14117 11
|
缓存 安全 Java
Java反射常见面试题最新总结
Java反射常见面试题总结
492 0
|
Linux 数据安全/隐私保护
debian使用桌面管理器管理多个桌面系统
在Debian 12中,初始安装了带KDE桌面的系统,KDE自带SDDM显示管理器。为切换桌面,安装了XFCE:`sudo apt install xfce4`。选择SDDM登录后点击“桌面会话”选XFCE。遇到问题:无法通过SDDM登录root。解决方案包括编辑`pam.d/sddm`和`root/.bashrc`,然后重启SDDM或系统。要彻底卸载XFCE,使用:`sudo apt remove *xfce4*`, `sudo apt autoremove`, `sudo apt clean`,重启后无XFCE选项。
|
数据处理 Android开发
关于安卓viewpager实现堆叠卡片交互
关于安卓viewpager实现堆叠卡片交互
762 1
|
数据可视化 定位技术
【threejs】可视化大屏酷炫3D地图附源码
【threejs】可视化大屏酷炫3D地图附源码
10970 130
【threejs】可视化大屏酷炫3D地图附源码
|
iOS开发 MacOS
WAServiceMainContext.js:2 Error: MiniProgramError
WAServiceMainContext.js:2 Error: MiniProgramError
526 0
|
存储 Linux KVM
虚拟化技术之KVM安装与使用
虚拟化技术之KVM安装与使用
|
存储 SQL JSON
大分区表高并发性能提升100倍?阿里云 RDS PostgreSQL 12 特性解读
世界上几乎最强大的开源数据库系统 PostgreSQL,于 2019 年 10 月 3 日发布了 12 版本,该版本已经在阿里云正式发布。PostgreSQL 12 在功能和性能上都有很大提升,如大分区表高并发性能提升百倍,B-tree 索引空间和性能优化,实现 SQL 2016 标准的 JSON 特性,支持多列 MCV(Most-Common-Value)统计,内联 CTE(Common table expressions)以及可插拔的表存储访问接口等。本文对部分特性进行解读。
3561 0
大分区表高并发性能提升100倍?阿里云 RDS PostgreSQL 12 特性解读