diff Applications/Resources/Colormaps/GenerateColormaps.py @ 1586:b5417e377636

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 22 Oct 2020 16:17:10 +0200
parents OrthancStone/Resources/Colormaps/GenerateColormaps.py@244ad1e4e76a
children 8c5f9864545f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Applications/Resources/Colormaps/GenerateColormaps.py	Thu Oct 22 16:17:10 2020 +0200
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+import array
+import matplotlib.pyplot as plt
+
+def GenerateColormap(name):
+    colormap = []
+
+    for gray in range(256):
+        if name == 'red':
+            color = (gray / 255.0, 0, 0)
+        elif name == 'green':
+            color = (0, gray / 255.0, 0)
+        elif name == 'blue':
+            color = (0, 0, gray / 255.0)
+        else:
+            color = plt.get_cmap(name) (gray)
+
+        colormap += map(lambda k: int(round(color[k] * 255)), range(3))
+
+    colormap[0] = 0
+    colormap[1] = 0
+    colormap[2] = 0
+
+    return array.array('B', colormap).tostring()
+
+
+for name in [ 
+        'hot', 
+        'jet', 
+        'blue',
+        'green',
+        'red',
+]:
+    with open('%s.lut' % name, 'w') as f:
+        f.write(GenerateColormap(name))