Function iacolormap

Synopse

Create a colormap table.

  • ct = iacolormap(type='gray')
    • ct: Image.
    • type: String. Type of the colormap. Options: 'gray', 'hsv', 'hot', 'cool', 'bone','copper', 'pink'.
01. import numpy as np
02. import colorsys
03. import ia636 as ia
04. 
05. def iacolormap(type='gray'):
06. 
07.     if type == 'gray':
08.         ct = np.transpose(np.resize(np.arange(256), (3,256)))
09.     elif type == 'hsv':
10.         h = np.arange(256)/255.
11.         s = np.ones(256)
12.         v = np.ones(256)
13.         ct = ia.ianormalize(np.reshape(map(colorsys.hsv_to_rgb, h, s, v), (256,3)), [0,255]).astype(np.uint8)
14.     elif type == 'hot':
15.         n = np.floor(256./3) #np.floor(3./8*256)
16.         r = np.concatenate((np.arange(1,n+1)/n, np.ones(256-n)), 1)[:,np.newaxis]
17.         g = np.concatenate((np.zeros(n), np.arange(1,n+1)/n, np.ones(256-2*n)), 1)[:,np.newaxis]
18.         b = np.concatenate((np.zeros(2*n), np.arange(1,256-2*n+1)/(256-2*n)), 1)[:,np.newaxis]
19.         ct = ia.ianormalize(np.concatenate((r,g,b), 1), [0,255]).astype(np.uint8)
20.     elif type == 'cool':
21.         r = (np.arange(256)/255.)[:,np.newaxis]
22.         ct = ia.ianormalize(np.concatenate((r, 1-r, np.ones((256,1))), 1), [0,255]).astype(np.uint8)
23.     elif type == 'bone':
24.         ct = ia.ianormalize((7 * iacolormap('gray') + iacolormap('hot')[:,::-1]) / 8., [0,255]).astype(np.uint8)
25.     elif type == 'copper':
26.         cg = iacolormap('gray')/255.
27.         fac = np.dot(cg, [[1.25,0,0],[0,0.7812,0],[0,0,0.4975]])
28.         aux = np.minimum(1, fac)
29.         ct = ia.ianormalize(aux).astype(np.uint8)
30.     elif type == 'pink':
31.         ct = ia.ianormalize(np.sqrt((2*iacolormap('gray') + iacolormap('hot')) / 3), [0,255]).astype(np.uint8)
32.     else:
33.         ct = np.zeros((256,3))
34.     return ct

Description

Create pseudo colormap tables.

Examples

Example 1

01. import numpy as np
02. import ia636 as ia
03. 
04. tables = [ 'gray', 'hsv', 'hot', 'cool', 'bone','copper', 'pink']
05. 
06. r,f = np.indices((10,256), 'uint8')
07. adshow(f, 'gray scale')
08. 
09. for table in tables:
10.     cm = ia.iacolormap(table)
11.     g = ia.iaapplylut(f, cm)
12.     adshow(g, table)

gray scale

gray

hsv

hot

cool

bone

copper

pink

Example 2

Plotting the colormap table

1. for table in tables:
2.     Tc = ia.iacolormap(table)
3.     adshow(ia.iaplot([Tc[:,0], Tc[:,1], Tc[:,2]] ),table)

gray

hsv

hot

cool

bone

copper

pink

Example 3

With image

1. f = adreadgray('MVBook/retina.tif')
2. for table in tables:
3.     Tc = ia.iacolormap(table)
4.     g = ia.iaapplylut(f,Tc)
5.     adshow(g, table)

gray

hsv

hot

cool

bone

copper

pink

References