-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_class.py
393 lines (288 loc) · 12.3 KB
/
multiple_class.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# -*- coding: utf-8 -*-
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QToolButton, QComboBox, QListView, QApplication, QDialog
from charts import ChartPatternsClass
from deltas_class import GetDeltasClass
from getImageColors import getImageColors
from metadata_class import GetMetadataClass
#from mtf_class import GetMTFClass
from mtf_rgb import GetMTFClassRGB
from multiple_stats_guid import multipleStatsUI
from noise_class import GetNoiseClass
from oecf_class import GetOECFClass
from readCGATS import GetCGATSClass
try:
_encoding = QtWidgets.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtWidgets.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtWidgets.QApplication.translate(context, text, disambig)
class MultipleTestClass(object):
def __init__(self, coordenadasReales, multipleFiles, CEGATSpath, perfil_nuevo, chartIndex):
# super(UI_Multiple, self).__init__(multipleFiles, coordenadasReales, CEGATSpath, perfil_nuevo, chartIndex)
# self.a = QtGui.QApplication(sys.argv)
self.multipleFiles = multipleFiles
self.coords = coordenadasReales
self.cgats = CEGATSpath
self.icc = perfil_nuevo
self.chartIndex = chartIndex
self.charts = ChartPatternsClass()
def setupUi(self, MultipleDialog):
MultipleDialog.setObjectName("MultipleDialog")
MultipleDialog.setFixedSize(299, 239)
MultipleDialog.setWindowTitle(_translate("MultipleDialog", "ImageQA Batch Analysis", None))
self.listView = QListView(MultipleDialog)
self.listView.setGeometry(QtCore.QRect(20, 20, 261, 141))
self.listView.setObjectName("listView")
model = QtGui.QStandardItemModel()
self.listView.setModel(model)
arr = []
for i in self.multipleFiles:
# print( os.path.basename( str(i) ) )
item = QtGui.QStandardItem(os.path.basename(str(i)))
model.appendRow(item)
arr.append(str(i))
self.comboBox = QComboBox(MultipleDialog)
self.comboBox.setGeometry(QtCore.QRect(20, 180, 191, 26))
self.comboBox.setObjectName("comboBox")
items = ["--- Select----", "Delta-e", "OECF", "MTF", "NOISE", "Sensitometry"]
self.comboBox.addItems(items)
switch = self.charts.get_switch(self.chartIndex)
self.comboBox.model().item(1).setEnabled(switch[0])
self.comboBox.model().item(2).setEnabled(switch[5])
self.comboBox.model().item(3).setEnabled(switch[3])
self.comboBox.model().item(4).setEnabled(switch[4])
self.comboBox.model().item(5).setEnabled(switch[4])
self.comboBox.currentIndexChanged.connect(self.enable_go_button)
self.goButton = QToolButton(MultipleDialog)
self.goButton.setGeometry(QtCore.QRect(230, 170, 51, 41))
self.goButton.setObjectName("toolButton")
self.goButton.setText(_translate("MultipleDialog", "GO", None))
self.goButton.setEnabled(False)
self.goButton.clicked.connect(self.open_stats)
QtCore.QMetaObject.connectSlotsByName(MultipleDialog)
def check_item(self, itemName):
items_list = self.listView.model().findItems(itemName, QtCore.Qt.MatchExactly)
item = items_list[0].row()
self.listView.model().item(item).setBackground(QtGui.QColor("#7fc97f"))
QApplication.processEvents()
def reset_check_item(self):
for item in range(self.listView.model().rowCount()):
self.listView.model().item(item).setBackground(QtGui.QColor("#ffffff"))
def enable_go_button(self):
self.reset_check_item()
if self.comboBox.currentIndex() > 0:
self.goButton.setEnabled(True)
else:
self.goButton.setEnabled(False)
def open_stats(self):
index = self.comboBox.currentIndex()
if index == 1:
stats = [("CIE76", self.get_means_color("CIE76")),
("CIE00", self.get_means_color("CIE00"))
]
elif index == 2:
stats = [
("OECF", self.get_m_oecf())
]
elif index == 3:
stats = [
("MTF", self.get_m_mtf())
]
elif index == 4:
stats = [
("SNR", self.get_m_noise())
]
elif index == 5:
stats = [
("SENSITOMETRY", self.get_m_sentitometry())
]
if stats[0][1] is not None:
dialog = QDialog()
dialog.ui = multipleStatsUI(stats)
dialog.ui.setupUi(dialog)
dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
dialog.exec_()
# empiezan las funcioens de analisis
def get_m_mtf(self):
o = {}
i = 0
for filename in self.multipleFiles:
#get_mtf = GetMTFClass(str(filename), self.coords)
#esf = get_mtf.compute_esf()
#lsf = get_mtf.compute_lsf(esf["xesf"], esf["esf"], esf["esf_smooth"])
#mtf = get_mtf.compute_mtf(lsf["lsf"], lsf["lsf_smooth"])
get_mtf_rgb = GetMTFClassRGB(str(filename), self.coords)
values = get_mtf_rgb.get_mtf_multiple()
if values:
#channel_mtf = values["channel_mtf"]
#channel_lsf = values["channel_lsf"]
#channel_esf = values["channel_esf"]
self.check_item(os.path.basename(str(filename)))
meta = GetMetadataClass(str(filename))
exposure = meta.get_exposure()
o[i] = {}
o[i]["FILENAME"] = os.path.basename(str(filename))
o[i]["SHUTTER"] = exposure[0]
o[i]["APERTURE"] = exposure[1]
o[i]["ISO"] = exposure[2]
o[i]["MTF"] = values["channel_mtf"]
i = i + 1
r = None
metrics = ["MTF50", "MTF30", "MTF10"]
if o and o[0]["MTF"] is not None:
r = []
for x in o:
rep = {
"filename": o[x]["FILENAME"],
"shutter": o[x]["SHUTTER"],
"aperture": o[x]["APERTURE"],
"iso": o[x]["ISO"],
"x_mtf_final": o[x]["MTF"]["GRAY"]["x_mtf_final"],
"mtf_final": o[x]["MTF"]["GRAY"]["mtf_final"],
}
for metric in metrics:
rep[metric] = o[x]["MTF"]["GRAY"][metric]["MTF"]
rep[metric + "MTFpercent"] = o[x]["MTF"]["GRAY"][metric]["MTFpercent"]
rep[metric+"LPmm"] = o[x]["MTF"]["GRAY"][metric]["LPmm"]
rep[metric+"LW_PH"] = o[x]["MTF"]["GRAY"][metric]["LW_PH"]
rep[metric+"LPH"] = o[x]["MTF"]["GRAY"][metric]["LPH"]
rep[metric + "lpNyquist"] = o[x]["MTF"]["GRAY"][metric]["lpNyquist"]
rep[metric + "imgLPmm"] = o[x]["MTF"]["GRAY"][metric]["imgLPmm"]
rep[metric + "lpPercent"] = o[x]["MTF"]["GRAY"][metric]["lpPercent"]
r.append(rep)
return r
def get_m_noise(self):
o = {}
i = 0
for filename in self.multipleFiles:
meta = GetMetadataClass(str(filename))
exposure = meta.get_exposure()
valoresLAB = getImageColors(self.coords, str(filename), self.icc)
noise = GetNoiseClass(valoresLAB.get_rgb_values())
self.check_item(os.path.basename(str(filename)))
o[i] = {}
o[i]["FILENAME"] = os.path.basename(str(filename))
o[i]["ISO"] = exposure[2]
o[i]["SNRRGB"] = noise.getRGB()
o[i]["SNR"] = noise.getSNR()
i = i + 1
r = []
for x in o:
# filename = o[x]["FILENAME"]
iso = o[x]["ISO"]
fn = o[x]["FILENAME"]
items = o[x]["SNR"]
#r.append(((iso, fn), items))
r.append({ "File": fn,
"ISO":iso,
"curve": items["curve"],
"stats": items["stats"],
"x_axis": items["x_axis"]
})
return r
def get_m_deltas(self):
o = {}
i = 0
for filename in self.multipleFiles:
valoresLAB = getImageColors(self.coords, str(filename), self.icc)
valoresReferencia = GetCGATSClass(self.cgats)
deltas = GetDeltasClass(valoresLAB.get_lab_values(), valoresReferencia.labCGATS)
self.check_item(os.path.basename(str(filename)))
o[i] = {}
o[i]["FILENAME"] = os.path.basename(str(filename))
o[i]["CIE76"] = deltas.get_cie76()
o[i]["CIE00"] = deltas.get_cie00()
# o[i]["CIE94"] = deltas.getCIE94()
# o[i]["CMC"] = deltas.getCMC()
i = i + 1
return o
def get_means_color(self, field):
arr = self.get_m_deltas()
o = []
for x in arr:
filename = arr[x]["FILENAME"]
means = arr[x][field]["stats"]
o.append((filename, float(means['Average'])))
return o
# print(o)
def get_m_dev(self):
arr = self.get_m_deltas()
patches = self.charts.get_gray_scale(self.chartIndex)
o = []
for x in arr:
filename = arr[x]["FILENAME"]
items = arr[x]["DEV"]
scale = [items[i] for i in patches]
o.append((filename, scale))
return o
# print(o)
def get_patch_name(self, reference):
patchName = []
for patch in reference:
patchName.append(patch["SAMPLE_ID"])
return patchName
def get_density_name(self, reference):
patchName = []
for patch in reference:
patchName.append(patch["D_VIS"])
return patchName
def get_m_oecf(self):
o = {}
i = 0
for filename in self.multipleFiles:
meta = GetMetadataClass(str(filename))
filen = os.path.basename(str(filename))
exposure = meta.get_exposure() + (filen,)
valoresLAB = getImageColors(self.coords, str(filename), self.icc)
valoresReferencia = GetCGATSClass(self.cgats)
#OECF = GetOECFClass(valoresLAB.get_rgb_values(), valoresReferencia.RGB, valoresLAB.get_lab_values(),
# valoresReferencia.labCGATS)
OECF = GetOECFClass(valoresLAB.get_rgb_values(), valoresLAB.get_lab_values(), valoresReferencia.labCGATS)
self.check_item(os.path.basename(str(filename)))
o[i] = {}
o[i]["FILENAME"] = os.path.basename(str(filename))
o[i]["OECF"] = OECF.get_oecf_values("OECF")
o[i]["shutter"] = exposure[0]
o[i]["aperture"] = exposure[1]
o[i]["ISO"] = exposure[2]
i = i + 1
s = []
for x in o:
filename = o[x]["FILENAME"]
items = o[x]["OECF"]
shutter = o[x]["shutter"]
aperture = o[x]["aperture"]
ISO = o[x]["ISO"]
# scale = [items[i] for i in patches]
#arrD = []
#for y in items[0]:
# arrD.append(y)
s.append({ "File": filename,
"shutter": shutter,
"aperture":aperture,
"iso": ISO,
"curve": items["curve"],
"stats": items["stats"],
"x_axis": items["x_axis"]
})
#s.append((exposure, arrD))
return s
def get_m_sentitometry(self):
patches = self.charts.get_gray_scale(self.chartIndex)
o = []
for filename in self.multipleFiles:
meta = GetMetadataClass(str(filename))
filen = os.path.basename(str(filename))
exposure = meta.get_exposure() + (filen,)
self.check_item(os.path.basename(str(filename)))
# print(exposure)
valoresLAB = getImageColors(self.coords, str(filename), self.icc)
LAB = valoresLAB.get_lab_values()
scale = []
for x in patches:
scale.append(LAB[x - 1]['LAB'][0])
o.append((exposure, scale))
return o