[iargb2ycbcr] [Up] [iaffine] | Color Processing |
Convert RGB values to YCbCr color space.
>>> import Numeric
>>> r = [[4,5,6],[4,2,4]]
>>> g = [[0,1,2],[0,4,0]]
>>> b = [[1,0,2],[1,2,2]]
>>> f = Numeric.zeros((3,2,3))
>>> f[0,:,:], f[1,:,:], f[2,:,:] = r, g, b
>>> print f[0,:,:]
[[4 5 6] [4 2 4]]
>>> print f[1,:,:]
[[0 1 2] [0 4 0]]
>>> print f[2,:,:]
[[1 0 2] [1 2 2]]
>>> g = iargb2ycbcr(f)
>>> f_ = iaycbcr2rgb(g)
>>> print f_[0,:,:]
[[ 3.999924 4.998288 5.99892 ] [ 3.999924 1.998408 4.00068 ]]
>>> print f_[1,:,:]
[[ 7.35000000e-004 1.00119700e+000 2.00078000e+000] [ 7.35000000e-004 3.99957600e+000 4.42000000e-004]]
>>> print f_[2,:,:]
[[ 1.002063 0.002869 2.00228 ] [ 1.002063 1.99917 2.001598]]
def iaycbcr2rgb(f): g = 0.*f g[0,:,:] = 1.164*(f[0,:,:]-16) + 1.596*(f[2,:,:]-128) g[1,:,:] = 1.164*(f[0,:,:]-16) - 0.392*(f[1,:,:]-128) - 0.813*(f[2,:,:]-128) g[2,:,:] = 1.164*(f[0,:,:]-16) + 2.017*(f[1,:,:]-128) return g
[iargb2ycbcr] [Up] [iaffine] | |