从矩阵表 YCbCr 到 RGB

发布于 2024-09-29 06:34:00 字数 158 浏览 6 评论 0原文

下面是将 RGB 转换为 YCbCr 的矩阵。你能告诉我如何获得将 YCbCr 转换为 RGB 的公式吗? 我的意思是,我有可用的 YCbCr 值,并且我想从中获取 RGB。 RGB 转 YUV 图像

Below is a matrix to convert RGB to YCbCr. Can you tell me how can I get formula to convert YCbCr to RGB?
I mean, I have YCbCr value available and I want to get RGB from it.
RGB to YUV Image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

于我来说 2024-10-06 06:34:00

如果您询问公式是如何推导的,您可能需要搜索“颜色坐标系”。 此页面特别对 YCbCr 空间进行了很好的讨论。

我们知道几乎任何颜色都可以表示为红、绿、蓝的线性组合。但是您可以转换(或“旋转”)该坐标系,使三个基本元素不再是 RGB,而是其他元素。对于YCbCr,Y层是亮度层,Cb和Cr是两个色度层。 Cb 与蓝色的相关性更密切,Cr 与红色的相关性更密切。

YCbCr 通常是首选,因为人类视觉系统对亮度的变化比对色度的定量等效变化更敏感。因此,诸如 JPEG 之类的图像编码器可以比亮度层更多地压缩两个色度层,从而获得更高的压缩比。

编辑:我误解了这个问题。 (您应该编辑它以澄清。)这是从 YCbCr 获取 RGB 的公式,取自上面的 链接

r   =   1.0 * y'    + 0 * cB    + 1.402 * cR
g   =   1.0 * y'    - 0.344136 * cB - 0.714136 * cR
b   =   1.0 * y'    + 1.772 * cB    + 0 * cR

If you are asking how the formula is derived, you may want to search for "color coordinate systems". This page has a good discussion on the YCbCr space, in particular.

We know that almost any color can be represented as a linear combination of red, green, and blue. But you can transform (or "rotate") that coordinate system such that the three basis elements are no longer RGB, but something else. In the case of YCbCr, the Y layer is the luminance layer, and Cb and Cr are the two chrominance layers. Cb correlates more closely to blue, and Cr correlates more closely to red.

YCbCr is often preferred because the human visual system is more sensitive to changes in luminance than quantitatively equivalent changes in chrominance. Therefore, an image coder such as JPEG can compress the two chrominance layers more than the luminance layer, resulting in a higher compression ratio.

EDIT: I misunderstood the question. (You should edit it to clarify.) Here is the formula to get RGB from YCbCr, taken from the above link:

r   =   1.0 * y'    + 0 * cB    + 1.402 * cR
g   =   1.0 * y'    - 0.344136 * cB - 0.714136 * cR
b   =   1.0 * y'    + 1.772 * cB    + 0 * cR
你穿错了嫁妆 2024-10-06 06:34:00

我不会考虑 round 部分,但由于 M 看起来是可逆的:

alt text

您可以对结果向量进行舍入。

I'm not going to account for the round portion, but since M looks invertible:

alt text

You can round the resulting vector.

友欢 2024-10-06 06:34:00
Y = 0.2126*(219/255)*R + 0.7152(219/255)*G + 0.0722*(219/255)*B + 16
CB = -0.2126/1.18556*(224/255)*R - 0.7152/1.8556(224/255)*G + 0.5*(219/255)*B + 128
CR = 0.5*(224/255)*R - 0.7152/1.5748(224/255)*G - 0.0722/1.5748*(224/255)*B + 128
Y = 0.2126*(219/255)*R + 0.7152(219/255)*G + 0.0722*(219/255)*B + 16
CB = -0.2126/1.18556*(224/255)*R - 0.7152/1.8556(224/255)*G + 0.5*(219/255)*B + 128
CR = 0.5*(224/255)*R - 0.7152/1.5748(224/255)*G - 0.0722/1.5748*(224/255)*B + 128
计㈡愣 2024-10-06 06:34:00

http://www.fourcc.org/fccyvrgb.php 具有 YUV 到 RGB 的转换。

http://www.fourcc.org/fccyvrgb.php has YUV to RGB conversions.

转换为浮点数并应用(因为系数为 BT.709-2):

https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion

1   0        1.5748
1  -0.1873  -0.4681 
1   1.8556   0

Convert to float and apply (since the coeff. are BT.709-2):

https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion

1   0        1.5748
1  -0.1873  -0.4681 
1   1.8556   0
治碍 2024-10-06 06:34:00

这些是适用于 0-255 颜色的方程式。在这里,它们是 C 语言

RGB 到 YCBCR

y = 0.299* (r) + 0.587 * (g)    + 0.114* (b);
cb= 128 - 0.168736* (r) - 0.331364 * (g)    + 0.5* (b);
cr= 128 + 0.5* (r)  - 0.418688 * (g)    - 0.081312* (b);
    

YCBCR 到 RGB

r = (y) + 1.402 * (cr -128);
g = (y) - 0.34414 * (cb - 128) - 0.71414 * (cr - 128);
b = (y) + 1.772 * (cb - 128);

These are the equations that work for 0-255 colors. Here they are in C

RGB to YCBCR

y = 0.299* (r) + 0.587 * (g)    + 0.114* (b);
cb= 128 - 0.168736* (r) - 0.331364 * (g)    + 0.5* (b);
cr= 128 + 0.5* (r)  - 0.418688 * (g)    - 0.081312* (b);
    

YCBCR to RGB

r = (y) + 1.402 * (cr -128);
g = (y) - 0.34414 * (cb - 128) - 0.71414 * (cr - 128);
b = (y) + 1.772 * (cb - 128);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文