如何转换RGB - > YUV - > RGB(双向) [英] How to convert RGB -> YUV -> RGB (both ways)

查看:252
本文介绍了如何转换RGB - > YUV - > RGB(双向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想的一对转换算法,一是从RGB到YUV,其他从YUV到RGB,这是彼此的逆。也就是说,一个往返转换应保留值不变。 (如果你喜欢,请用Y'UV,YUV,的YCbCr,YUV的YPbPr)

I want a pair of conversion algorithms, one from RGB to YUV, the other from YUV to RGB, that are inverses of each other. That is, a round-trip conversion should leave the value unchanged. (If you like, replace YUV with Y'UV, YUV, YCbCr, YPbPr.)

这样的事情确实存在?如果是这样,那是什么?

Does such a thing exist? If so, what is it?

发布解决方案(<一个href=\"http://stackoverflow.com/questions/1737726/how-to-perform-rgb-yuv-conversion-in-c-c/1737741#1737741\">How执行RGB-&GT; YUV转换在C / C ++ , http://www.fourcc.org/fccyvrgb? PHP http://en.wikipedia.org/wiki/YUV )仅逆(二3×3矩阵是逆),省略夹紧到[0,255]时。但省略了夹紧允许之类的东西负的亮度,这在YUV空间发挥欢快严重破坏的图像处理。保持夹紧,使转换的非线性,这使得它非常棘手定义的逆

Posted solutions (How to perform RGB->YUV conversion in C/C++?, http://www.fourcc.org/fccyvrgb.php, http://en.wikipedia.org/wiki/YUV) are only inverses (the two 3x3 matrices are inverses), when omitting the clamping to [0,255]. But omitting that clamping allows things like negative luminance, which plays merry havoc with image processing in YUV space. Retaining the clamping makes the conversion nonlinear, which makes it tricky to define an inverse.

推荐答案

是的,可逆的转换存在。

Yes, invertible transformations exist.

equasys有限公司帖子来自RGB到YUV,YCbCr和的YPbPr可逆的转换,与一起解释什么情况下每个适合,这夹紧真的是什么,并链接到引用。 (就像一个良好的SO回答。)

equasys GmbH posts invertible transformations from RGB to YUV, YCbCr, and YPbPr, along with explanations of which situation each is appropriate for, what this clamping is really about, and links to references. (Like a good SO answer.)

有关我自己的应用程序(JPG图像,而不是模拟电压)的YCbCr是合适的,所以我写了code为这两个转变。事实上,和 - 背再次值由小于1份在256不同,对于许多图像;和 - 前后和图像是视觉区分。

For my own application (jpg images, not analog voltages) YCbCr was appropriate, so I wrote code for those two transformations. Indeed, there-and-back-again values differed by less than 1 part in 256, for many images; and the before-and-after images were visually indistinguishable.

PIL的色彩空间转换的YCbCr - &GT; RGB 获得信贷提equasys的网页。

PIL's colour space conversion YCbCr -> RGB gets credit for mentioning equasys's web page.

其他答案,这可能对equasys的precision和简洁疑惑改善:

Other answers, that could doubtfully improve on equasys's precision and concision:

  • https://code.google.com/p/imagestack/ includes rgb_to_x and x_to_rgb functions, but I didn't try to compile and test them.

科里·纳尔逊的答案链接至code。与类似的功能,但它说,
反转是不可能的,一般,矛盾equasys。

Cory Nelson's answer links to code with similar functions, but it says that inversion's not possible in general, contradicting equasys.

FFmpeg的,OpenCV的,VLFeat或ImageMagick的的来源$ C ​​$ C。

The source code of FFmpeg, OpenCV, VLFeat, or ImageMagick.

这篇关于如何转换RGB - &GT; YUV - &GT; RGB(双向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆