Mercurial > hg > orthanc-stone
annotate Applications/Resources/Colormaps/GenerateColormaps.py @ 1985:bb307007f8e2
improved interaction with rectangle probes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Oct 2022 15:01:09 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
7 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
8 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
9 # 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
|
10 # 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
|
11 # 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
|
12 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
13 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
14 # 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
|
15 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
17 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
18 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
19 # 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
|
20 # 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
|
21 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
22 |
0 | 23 import array |
24 import matplotlib.pyplot as plt | |
25 | |
26 def GenerateColormap(name): | |
27 colormap = [] | |
28 | |
29 for gray in range(256): | |
30 if name == 'red': | |
31 color = (gray / 255.0, 0, 0) | |
32 elif name == 'green': | |
33 color = (0, gray / 255.0, 0) | |
34 elif name == 'blue': | |
35 color = (0, 0, gray / 255.0) | |
36 else: | |
37 color = plt.get_cmap(name) (gray) | |
38 | |
39 colormap += map(lambda k: int(round(color[k] * 255)), range(3)) | |
40 | |
1743 | 41 #colormap[0] = 0 |
42 #colormap[1] = 0 | |
43 #colormap[2] = 0 | |
0 | 44 |
45 return array.array('B', colormap).tostring() | |
46 | |
47 | |
48 for name in [ | |
49 'hot', | |
50 'jet', | |
51 'blue', | |
52 'green', | |
53 'red', | |
54 ]: | |
55 with open('%s.lut' % name, 'w') as f: | |
56 f.write(GenerateColormap(name)) |