0
|
1 #!/usr/bin/python
|
|
2
|
|
3 import array
|
|
4 import matplotlib.pyplot as plt
|
|
5
|
|
6 def GenerateColormap(name):
|
|
7 colormap = []
|
|
8
|
|
9 for gray in range(256):
|
|
10 if name == 'red':
|
|
11 color = (gray / 255.0, 0, 0)
|
|
12 elif name == 'green':
|
|
13 color = (0, gray / 255.0, 0)
|
|
14 elif name == 'blue':
|
|
15 color = (0, 0, gray / 255.0)
|
|
16 else:
|
|
17 color = plt.get_cmap(name) (gray)
|
|
18
|
|
19 colormap += map(lambda k: int(round(color[k] * 255)), range(3))
|
|
20
|
|
21 colormap[0] = 0
|
|
22 colormap[1] = 0
|
|
23 colormap[2] = 0
|
|
24
|
|
25 return array.array('B', colormap).tostring()
|
|
26
|
|
27
|
|
28 for name in [
|
|
29 'hot',
|
|
30 'jet',
|
|
31 'blue',
|
|
32 'green',
|
|
33 'red',
|
|
34 ]:
|
|
35 with open('%s.lut' % name, 'w') as f:
|
|
36 f.write(GenerateColormap(name))
|