RGB到YCbCr转换问题 [英] RGB to YCbCr Conversion problems
本文介绍了RGB到YCbCr转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将RGB图像转换为YCbCr颜色空间,但有一些颜色偏移问题,我使用所有公式,得到相同的结果。
i need convert RGB image to YCbCr colour space, but have some colour shift problems, i used all formulas and got the same result.
p>
Formula in python
cbcr[0] = int(0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]) #Y
cbcr[1] = int(-0.1687*rgb[0] - 0.3313*rgb[1] + 0.5*rgb[2] + 128) #Cb
cbcr[2] = int( 0.5*rgb[0] - 0.4187*rgb[1] - 0.0813*rgb[2] + 128) #Cr
$ b b
我知道我应该用不同的方式来记录数据,但是我得到了错误的颜色结果。
I know that i should get the same image with different way to record data, but i got wrong colour result.
http://i.imgur.com/zHuv8yq.png 原创
http://i.imgur.com/Ek2WEA1.png 结果
那么我如何获得正常图像或将RGB PNG转换为YCbCr 4:2:2?
So how i can get normal image or convert RGB PNG into YCbCr 4:2:2?
推荐答案
p>这应该工作(大约)
This should work (approximately)
def _ycc(r, g, b): # in (0,255) range
y = .299*r + .587*g + .114*b
cb = 128 -.168736*r -.331364*g + .5*b
cr = 128 +.5*r - .418688*g - .081312*b
return y, cb, cr
def _rgb(y, cb, cr):
r = y + 1.402 * (cr-128)
g = y - .34414 * (cb-128) - .71414 * (cr-128)
b = y + 1.772 * (cb-128)
return r, g, b
>>> c = _ycc(10, 20, 30)
>>> _rgb(*c)
(10.000005760000002, 20.000681726399996, 29.996457920000005)
这篇关于RGB到YCbCr转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文