-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXYZtoRGB.py
137 lines (93 loc) · 3.01 KB
/
XYZtoRGB.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# import pandas as pd
import numpy as np
from skimage import data
from skimage.color import xyz2rgb,rgb2xyz
import cv2 as cv2
from colormath.color_objects import XYZColor, sRGBColor
from colormath.color_conversions import convert_color
import os
# path_files = os.getcwd()
# os.path.join(path_files, )
def txt2XYZ(path1, path2, path3, folderout, filename, height,width):
with open(path1) as f:
linesX = f.readlines()
with open(path2) as f:
linesY = f.readlines()
with open(path3) as f:
linesZ = f.readlines()
Ylist = []
Xi = []
Yi = []
Cxlist = []
Cylist = []
fl = []
xi = 0
# height,width = 3264, 4896
line_size = width*4
data = np.zeros([height,width,3])
new_line = ''
linesX = linesX[8:len(linesX)]
linesY = linesY[8:len(linesY)]
linesZ = linesZ[8:len(linesZ)]
xn,yn,zn = 0,0,0
Xa = np.zeros([height, width])
Ya = np.zeros([height, width])
Za = np.zeros([height, width])
cx = np.zeros([height, width])
cy = np.zeros([height, width])
imgr = np.zeros([height, width, 3])
print("Generating X Y Z arrays")
for i in range(0,height):
new_line = ''
lineX = linesX[i]
lineY = linesY[i]
lineZ = linesZ[i]
rx = lineX.split()
ry = lineY.split()
rz = lineZ.split()
for yi in range(0,width-1):
X = float(rx[yi])
Y = float(ry[yi])
Z = float(rz[yi])
Xa[xi, yi] = X
Ya[xi, yi] = Y
Za[xi, yi] = Z
cx[xi, yi] = X/(X+Y+Z)
cy[xi, yi] = Y/(X+Y+Z)
xi = xi +1
print("Savings Arrays")
with open(os.path.join(folderout,'X.npy'), 'wb') as f:
np.save(f, Xa)
with open(os.path.join(folderout,'Y.npy'), 'wb') as f:
np.save(f, Ya)
with open(os.path.join(folderout,'Z.npy'), 'wb') as f:
np.save(f, Za)
with open(os.path.join(folderout,'cx.npy'), 'wb') as f:
np.save(f, cx)
with open(os.path.join(folderout,'cy.npy'), 'wb') as f:
np.save(f, cy)
Ya2 = Ya
img1 = cv2.merge((Xa/np.max(Xa), Ya/np.max(Ya), Za/np.max(Za)))
imgrgb1 = xyz2rgb(img1)
################## noramlized image using function ###############
out = np.zeros(Xa.shape, np.double)
Xa = cv2.normalize(Xa, out, 1.0, 0.0, cv2.NORM_MINMAX)
out = np.zeros(Ya.shape, np.double)
Ya = cv2.normalize(Ya, out, 1.0, 0.0, cv2.NORM_MINMAX)
out = np.zeros(Za.shape, np.double)
Za = cv2.normalize(Za, out, 1.0, 0.0, cv2.NORM_MINMAX)
img2 = cv2.merge((Ya, Xa, Za))## un poco de azul similar a la imagen simulada
imgrgb2 = xyz2rgb(img2)
R, G, B = cv2.split(imgrgb2)
imgrgb3 = cv2.merge((B, G, R))
imgrgb3 = imgrgb3*255
print(os.path.join(folderout, filename))
cv2.imwrite(os.path.join(folderout, filename), imgrgb3)
return os.path.join(folderout, filename)
# path1 = '/home/jorge/work/speos/GUI_v5.2/txt_files/xyz_files/Akamai3_X.txt'
# path2 = '/home/jorge/work/speos/GUI_v5.2/txt_files/xyz_files/Akamai3_Y.txt'
# path3 = '/home/jorge/work/speos/GUI_v5.2/txt_files/xyz_files/Akamai3_Z.txt'
# height,width = 3264, 4896
# folderout = '/home/jorge/work/speos/GUI_v5.2/txt_files/out'
# filename = 'RGB.png'
# txt2XYZ(path1, path2, path3, folderout, filename, height,width)