-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneutralidad_guid.py
178 lines (134 loc) · 7.61 KB
/
neutralidad_guid.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
# -*- coding: utf-8 -*-
import time
import numpy as np
import pyqtgraph as pg
import pyqtgraph.exporters
from PyQt5 import QtCore, QtGui, QtWidgets
from app_paths import DefinePathsClass
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 FallOffUI(object):
def __init__(self, imgStats, img):
self.imgStats = imgStats
# se rota la imagen porque en la representación se cambian los ejes
self.np_im = np.rot90(img, 3)
def setupUi(self, falloff_dialog):
falloff_dialog.setObjectName("Dialog")
falloff_dialog.setFixedSize(478, 550)
falloff_dialog.setWindowTitle(_translate("ImageQA", "ImageQA Light Falloff", None))
self.btCerrar = QtWidgets.QToolButton(falloff_dialog)
self.btCerrar.setGeometry(QtCore.QRect(20, 480, 30, 30))
self.btCerrar.setObjectName("btCerrar")
self.btCerrar.setIcon(QtGui.QIcon(DefinePathsClass.create_resource_path('close_64px.png')))
self.btCerrar.setIconSize(QtCore.QSize(30, 30))
self.btCerrar.setToolTip("Close")
self.verticalLayoutWidget = QtWidgets.QWidget(falloff_dialog)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 20, 441, 291))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
##--- GraphicsView (visor de imagenes )
# self.graphicsView = pg.GraphicsView( useOpenGL=False, background='k')
# self.graphicsView.setObjectName("graphicsView")
# self.verticalLayout.addWidget(self.graphicsView)
self.graphicsView = pg.PlotWidget(name='Plot1')
self.graphicsView.setLabel('left', 'Pixels', units='')
self.graphicsView.setLabel('bottom', 'Pixels', units='')
self.verticalLayout.addWidget(self.graphicsView)
self.verticalLayoutWidget_2 = QtWidgets.QWidget(falloff_dialog)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(20, 320, 321, 161))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 = QtWidgets.QHBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.btExportar = QtWidgets.QToolButton(falloff_dialog)
self.btExportar.setGeometry(QtCore.QRect(350, 320, 51, 41))
self.btExportar.setObjectName("Export")
self.btExportar.setIcon(QtGui.QIcon(DefinePathsClass.create_resource_path('pictures_64px.png')))
self.btExportar.setIconSize(QtCore.QSize(40, 40))
self.btExportar.clicked.connect(lambda state, y="neutrallity", x=self.graphicsView: self.export_graph(y, x))
self.toolButton_2 = QtWidgets.QToolButton(falloff_dialog)
self.toolButton_2.setGeometry(QtCore.QRect(410, 320, 51, 41))
self.toolButton_2.setObjectName("report")
self.toolButton_2.setIcon(QtGui.QIcon(DefinePathsClass.create_resource_path('report_64px.png')))
self.toolButton_2.setIconSize(QtCore.QSize(40, 40))
self.toolButton_2.setEnabled(False)
self.label = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label.setObjectName("label")
self.verticalLayout_2.addWidget(self.label)
self.label2 = QtWidgets.QLabel(self.verticalLayoutWidget_2)
self.label2.setObjectName("label2")
self.verticalLayout_2.addWidget(self.label2)
QtCore.QMetaObject.connectSlotsByName(falloff_dialog)
self.btCerrar.clicked.connect(falloff_dialog.close)
self.get_previsualization_image()
def get_previsualization_image(self):
#promedio = self.imgStats["mean"]
#min = self.imgStats["min"]
#max = self.imgStats["max"]
#desviacion = (max - min) / promedio
#print(desviacion)
self.getImage = pg.ImageItem()
self.getImage.setImage(self.np_im)
self.graphicsView.addItem(self.getImage)
'''
#esto es para representar la imagen con isolineas
self.my_dict = {}
i = 0
for x in range(min, max, 10):
if (x < promedio):
color = 'g'
elif (x > promedio):
color = 'b'
self.my_dict[i] = pg.IsocurveItem(level=x, pen=color)
self.my_dict[i].setParentItem(self.getImage)
self.my_dict[i].setData(pg.gaussianFilter(self.np_im, (2, 2)))
i += 1
c = pg.IsocurveItem(level=promedio, pen='r')
c.setParentItem(self.getImage)
c.setData(pg.gaussianFilter(self.np_im, (2, 2)))
'''
self.label.setText(self.print_stats_rgb(self.imgStats))
self.label2.setText(self.print_stats_lab(self.imgStats))
def print_stats_rgb(self, stats):
o = "<p style=\"line-height:120%; font-size:16px; color:#666\">"
o += "<italic style=\"font-size:14px; color:#666\">RGB </italic> <strong>Mean:</strong> " + str(
round(stats['mean'], 1)) + "<italic style=\"font-size:12px; color:#666\">cv</italic><br>"
o += "<italic style=\"font-size:14px; color:#666\">RGB </italic> <strong>Desv:</strong> " + str(
round(stats['desv'], 1)) + "<italic style=\"font-size:12px; color:#666\">cv</italic><br>"
o += "<italic style=\"font-size:14px; color:#666\">RGB </italic> <strong>Max:</strong> " + str(
round(stats['max'], 1)) + "<italic style=\"font-size:12px; color:#666\">cv</italic><br>"
o += "<italic style=\"font-size:14px; color:#666\">RGB </italic> <strong>Min:</strong> " + str(
round(stats['min'], 1)) + "<italic style=\"font-size:12px; color:#666\">cv</italic><br>"
o += "<strong>SNR:</strong> " + str(
round(stats['snr'], 1)) + "<italic style=\"font-size:12px; color:#666\">db</italic><br>"
o += "<strong>Non</strong> <span style=\"font-size:12px; color:#666\">Uniformity:</span> " + str(
round(stats['NonUniformity'], 1)) + "<italic style=\"font-size:12px; color:#666\">%</italic><br>"
o += "</p>"
return o
def print_stats_lab(self, stats):
o = "<p style=\"line-height:120%; font-size:16px; color:#666\">"
o += "<italic style=\"font-size:14px; color:#666\">L </italic><strong>Mean:</strong> " + str(
round(stats['l_mean'], 1)) + "<br>"
o += "<italic style=\"font-size:14px; color:#666\">L </italic><strong>Desv:</strong> " + str(
round(stats['l_desv'], 1)) + "<br>"
o += "<italic style=\"font-size:14px; color:#666\">C </italic><strong>Mean:</strong> " + str(
round(stats['c_mean'], 1)) + "<br>"
o += "<italic style=\"font-size:14px; color:#666\">C </italic><strong>Desv:</strong> " + str(
round(stats['c_desv'], 1)) + "<br>"
o += "<strong>Samples</strong> " + str(
round(stats['nPxLab'], 1)) + "<italic style=\"font-size:12px; color:#666\">pixels</italic><br>"
o += "</p>"
return o
def export_graph(self, key, plot):
fname = QtWidgets.QFileDialog.getExistingDirectory(None, 'Choose a directory for save Image')
# print(fname)
if fname != "":
timestr = time.strftime("%Y%m%d-%H%M%S")
exporter = pyqtgraph.exporters.ImageExporter(plot.plotItem)
exporter.parameters()['width'] = 800 # (note this also affects height parameter)
exporter.export(fname + "/" + key + "_" + str(timestr) + '.png')