[iahsv2rgb] [Up] [iaycbcr2rgb] Color Processing

iargb2ycbcr
Convert RGB to YCbCr color model.

Synopsis

g = iargb2ycbcr( f )

Implemented in Python.

Input

f Image. Gray-scale (uint8 or uint16) or binary image (logical).

True color RGB image.

Output

g Image. Gray-scale (uint8 or uint16) or binary image (logical).

YCbCr image.

Description

Convert RGB values to YCbCr color space.

Examples

>>> 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)

              
>>> print g[0,:,:]
[[ 17.126  17.789  18.746]
 [ 17.126  18.726  17.224]]
>>> print g[1,:,:]
[[ 127.847  126.969  127.408]
 [ 127.847  127.418  128.286]]
>>> print g[2,:,:]
[[ 129.685  129.827  129.756]
 [ 129.685  127.264  129.614]]

Source Code

def iargb2ycbcr(f):
    g = 0.*f
    g[0,:,:] =  f[0,:,:]*0.257 + f[1,:,:]*0.504 + f[2,:,:]*0.098 + 16
    g[1,:,:] = -f[0,:,:]*0.148 - f[1,:,:]*0.291 + f[2,:,:]*0.439 + 128
    g[2,:,:] =  f[0,:,:]*0.439 - f[1,:,:]*0.368 - f[2,:,:]*0.071 + 128
    return g
    
[iahsv2rgb] [Up] [iaycbcr2rgb] http://www.python.org