[iaapplylut] [Up] [iatcrgb2ind] Contrast Manipulation

iacolormap
Create a colormap table.

Synopsis

ct = iacolormap( type = 'gray' )

Implemented in Python.

Input

type String.

Type of the colormap. Options: 'gray', 'hsv', 'hot', 'cool', 'bone','copper', 'pink'.

Default: 'gray'

Output

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

Colormap table.

Description

Create a colormap table.

Examples

>>> f = ianormalize(iabwlp([150,150], 4, 1), [0,255]).astype('b')

              
>>> cm1 = iacolormap('hsv')

              
>>> g_cm1 = iaapplylut(f, cm1)

              
>>> cm2 = iacolormap('hot')

              
>>> g_cm2 = iaapplylut(f, cm2)

              
>>> iashow(f)
(150, 150) Min= 0 Max= 255 Mean=99.473 Std=61.67
>>> iashow(g_cm1)
(3, 150, 150) Min= 0 Max= 255 Mean=130.063 Std=112.33
>>> iashow(g_cm2)
(3, 150, 150) Min= 0 Max= 255 Mean=90.262 Std=104.93
f g_cm1 g_cm2

Source Code

def iacolormap(type='gray'):
    from Numeric import sqrt, transpose, resize, reshape, NewAxis, concatenate, arange, ones, zeros, matrixmultiply
    import colorsys
    if type == 'gray':
        ct = transpose(resize(arange(256), (3,256)))
    elif type == 'hsv':
        h = arange(256)/255.
        s = ones(256)
        v = ones(256)
        ct = ianormalize(reshape(map(colorsys.hsv_to_rgb, h, s, v), (256,3)), [0,255]).astype('b')
    elif type == 'hot':
        n = 1.*int(3./8*256)
        r = concatenate((arange(1,n+1)/n, ones(256-n)), 1)[:,NewAxis]
        g = concatenate((zeros(n), arange(1,n+1)/n, ones(256-2*n)), 1)[:,NewAxis]
        b = concatenate((zeros(2*n), arange(1,256-2*n+1)/(256-2*n)), 1)[:,NewAxis]
        ct = ianormalize(concatenate((r,g,b), 1), [0,255]).astype('b')
    elif type == 'cool':
        r = (arange(256)/255.)[:,NewAxis]
        ct = ianormalize(concatenate((r, 1-r, ones((256,1))), 1), [0,255]).astype('b')
    elif type == 'bone':
        ct = ianormalize((7*iacolormap('gray') + iacolormap('hot')[:,::-1]) / 8., [0,255]).astype('b')
    elif type == 'copper':
        ct = ianormalize(min(1, matrixmultiply(iacolormap('gray')/255., [[1.25,0,0],[0,0.7812,0],[0,0,0.4975]])), [0,255]).astype('b')
    elif type == 'pink':
        ct = ianormalize(sqrt((2*iacolormap('gray') + iacolormap('hot')) / 3), [0,255]).astype('b')
    else:
        ct = zeros((256,3))
    return ct
    

See also

iaapplylut Intensity image transform.
[iaapplylut] [Up] [iatcrgb2ind] http://www.python.org