[iatcrgb2ind] [Up] [iahsv2rgb] Color Processing

iargb2hsv
Convert RGB to HSV color model.

Synopsis

g = iargb2hsv( 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).

HSV color model.

Description

Converts red-green-blue colors to hue-saturation-value.

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 = iargb2hsv(f)

              
>>> print g[0,:,:]
[[ 0.95833333  0.03333333  0.        ]
 [ 0.95833333  0.33333333  0.91666667]]
>>> print g[1,:,:]
[[ 1.          1.          0.66666667]
 [ 1.          0.5         1.        ]]
>>> print g[2,:,:]
[[ 0.01568627  0.01960784  0.02352941]
 [ 0.01568627  0.01568627  0.01568627]]

Source Code

def iargb2hsv(f):
    from Numeric import ravel, reshape, transpose
    import colorsys
    g = map(colorsys.rgb_to_hsv, ravel(f[0,:,:]/255.), ravel(f[1,:,:]/255.), ravel(f[2,:,:]/255.))
    g = reshape(transpose(g), f.shape)
    return g
    
[iatcrgb2ind] [Up] [iahsv2rgb] http://www.python.org