Mercurial > hg > orthanc-stone
annotate Applications/Resources/Colormaps/GenerateColormaps.py @ 2129:169e2e586ef7 StoneWebViewer-2.2
closing StoneWebViewer-2.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 17:08:21 +0200 |
parents | 12528a80e3dd |
children | 3889ae96d2e9 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 | |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
3 # Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
7 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
9 # modify it under the terms of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
10 # as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
11 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
12 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
16 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
17 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
20 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
21 |
0 | 22 import array |
23 import matplotlib.pyplot as plt | |
24 | |
25 def GenerateColormap(name): | |
26 colormap = [] | |
27 | |
28 for gray in range(256): | |
29 if name == 'red': | |
30 color = (gray / 255.0, 0, 0) | |
31 elif name == 'green': | |
32 color = (0, gray / 255.0, 0) | |
33 elif name == 'blue': | |
34 color = (0, 0, gray / 255.0) | |
35 else: | |
36 color = plt.get_cmap(name) (gray) | |
37 | |
38 colormap += map(lambda k: int(round(color[k] * 255)), range(3)) | |
39 | |
1743 | 40 #colormap[0] = 0 |
41 #colormap[1] = 0 | |
42 #colormap[2] = 0 | |
0 | 43 |
44 return array.array('B', colormap).tostring() | |
45 | |
46 | |
47 for name in [ | |
48 'hot', | |
49 'jet', | |
50 'blue', | |
51 'green', | |
52 'red', | |
53 ]: | |
54 with open('%s.lut' % name, 'w') as f: | |
55 f.write(GenerateColormap(name)) |