-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowColors.py
67 lines (59 loc) · 2.22 KB
/
ShowColors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 21 13:36:42 2022
@author: Nafiseh Navabpour
This code will read a colormap and illustrates colors.
"""
from PIL import Image
import numpy as np
from xml.dom import minidom
#from HafezHelper2 import readColorMap
'''
This function read the XML file contains color maps,
return a list of [x,r,g,b]
'''
def readColorMap(colorMapFile, colorMapName):
try:
colorMapFile = open(colorMapFile)
xmldoc = minidom.parse(colorMapFile) #color map xml
itemlist = xmldoc.getElementsByTagName('ColorMap')
rgbCodes = []
colormapNameExist = False
for s in itemlist: #find color map
if (s.attributes['name'].value == colorMapName):
colormapNameExist = True
colorList = s.getElementsByTagName('Point')
for col in colorList: #collect color id relates to numbers
#input ('')
rgbCode = []
xv = "%.4f" % float(col.attributes['x'].value) #"%.2f"
rgbCode.append(xv)
rcode = round(float(col.attributes['r'].value))
gcode = round(float(col.attributes['g'].value))
bcode = round(float(col.attributes['b'].value))
rgbCode.append(rcode)
rgbCode.append(gcode)
rgbCode.append(bcode)
rgbCodes.append(rgbCode)
if (colormapNameExist == False):
print ('The color map name does not exist.')
except:
print ('The color map file does not exist.')
return (rgbCodes)
print ("Start!")
colorMapFile = 'C:/RainbowComplete.xml' #color maps
colorMapName = 'RainbowComplete' #Color map name
rgbCodes = readColorMap(colorMapFile, colorMapName)
data = np.zeros((2041, 10, 3), dtype=np.uint8)
i = 0
for line in rgbCodes:
color = line[1:]
#print ('color: ', color)
#input ('')
for j in range (0,10):
data[i, j] = color
img = Image.fromarray(data, 'RGB')
i += 1
img.save('ColorComplete.png')
img.show()
print ("The End!")