-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.py
289 lines (236 loc) · 14.5 KB
/
Program.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
import wx
import os
import cv2
import wx.grid as grid
from HeatMap import HeatMap
from UIPointsBased import Image
class MyFrame(wx.Frame):
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title= title, size = (700,735))
self.panel = MyPanel(self)
self.SetBackgroundColour("#2B4562")
self.SetForegroundColour("#2B4562")
ico = wx.Icon("icon.png", wx.BITMAP_TYPE_PNG)
self.SetIcon(ico)
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
# Path dialog
self.path_btn = wx.Button(self, label = "Path", pos = (10, 10), size = (125, 30))
self.path_btn.Bind(wx.EVT_BUTTON, self.getImageList)
# Starting image number - spin controller
starting_image_number_label = wx.StaticText(self, label = "Starting Image Number", pos = (10, 45))
starting_image_number_label.SetForegroundColour((255,255,255)) # set text color
self.starting_image_number_spin = wx.SpinCtrl(self, id=-1,pos = (10,60))
self.starting_image_number_spin.SetValue(4)
self.starting_image_number_spin.Bind(wx.EVT_SPINCTRL, self.getStartingImage)
# Ending image number - spin controller
ending_image_number_label = wx.StaticText(self, label = "Ending Image Number", pos = (10, 95))
ending_image_number_label.SetForegroundColour((255,255,255)) # set text color
self.ending_image_number_spin = wx.SpinCtrl(self, id=-1,pos = (10,110))
self.ending_image_number_spin.SetValue(96)
self.ending_image_number_spin.Bind(wx.EVT_SPINCTRL, self.getEndingImage)
# White value threshold - spin controller
white_value_threshold_label = wx.StaticText(self, label = "White Value Threshold", pos = (10, 145))
white_value_threshold_label.SetForegroundColour((255,255,255)) # set text color
self.white_value_threshold_spin = wx.SpinCtrl(self, id=-1,pos = (10,160))
self.white_value_threshold_spin.SetRange(0, 300)
self.white_value_threshold_spin.SetValue(100)
self.white_value_threshold_spin.Bind(wx.EVT_SPINCTRL, self.getWhiteThreshold)
# Minimum gap value (negative) - spin controller
minimum_gap_value_label = wx.StaticText(self, label = "Minumum Gap Value", pos = (10, 195))
minimum_gap_value_label.SetForegroundColour((255,255,255)) # set text color
self.minimum_gap_value_spin = wx.SpinCtrl(self, id=-1,pos = (10,210))
self.minimum_gap_value_spin.SetValue(35)
self.minimum_gap_value_spin.Bind(wx.EVT_SPINCTRL, self.getMinimumGapValue)
# Maximum gap value (negative) - spin controller
maximum_gap_value_label = wx.StaticText(self, label = "Maximum Gap Value", pos = (10, 245))
maximum_gap_value_label.SetForegroundColour((255,255,255)) # set text color
self.maximum_gap_value_spin = wx.SpinCtrl(self, id=-1,pos = (10,260))
self.maximum_gap_value_spin.SetRange(0, 350)
self.maximum_gap_value_spin.SetValue(135)
self.maximum_gap_value_spin.Bind(wx.EVT_SPINCTRL, self.getMaximumGapValue)
# Minimum pixel gap value - spin controller
min_gap_value_label = wx.StaticText(self, label = "Minimum Pixel Gap", pos = (10, 295))
min_gap_value_label.SetForegroundColour((255,255,255)) # set text color
self.min_gap_value_spin = wx.SpinCtrl(self, id=-1,pos = (10,310))
self.min_gap_value_spin.SetValue(2)
self.min_gap_value_spin.Bind(wx.EVT_SPINCTRL, self.getMinValue)
# Storage type (1 = xls, 2 = xlsx, 3 = csv) - radiobox
storage_type_options = ["Classic", "Modern", "CSV"]
self.storage_type_rbox = wx.RadioBox(self, label = "Storage Type", pos = (10, 345), choices = storage_type_options, style= wx.RA_SPECIFY_ROWS)
self.storage_type_rbox.SetForegroundColour((255,255,255)) # set text color
self.storage_type_rbox.Bind(wx.EVT_RADIOBOX, self.getStorageType)
# Heatmap setting (A for automatic else provide a number to compare sets of heatmaps) - radiobox
heatmap_setting_label = wx.StaticText(self, label = "Heatmap Setting", pos = (10, 448))
heatmap_setting_label.SetForegroundColour((255,255,255)) # set text color
self.heatmap_setting_textcontrol = wx.TextCtrl(self, pos = (10, 463), size = (125, 30))
self.heatmap_setting_textcontrol.SetValue("A")
self.heatmap_setting_textcontrol.Bind(wx.EVT_TEXT, self.getHeatmapSetting)
# Heatmap Slector
heatmap_selector_label = wx.StaticText(self, label = "Heatmap Slector", pos = (10, 498))
heatmap_selector_label.SetForegroundColour((255,255,255)) # set text color
heatmap_options = ["Original", "Viridis", "Plasma", "Inferno", "Magma"]
self.heatmap_selector_label_combobox = wx.ComboBox(self, pos=(10, 515), size = (125, 30), choices=heatmap_options, style=wx.CB_READONLY)
self.heatmap_selector_label_combobox.SetValue("Original")
self.heatmap_selector_label_combobox.Bind(wx.EVT_COMBOBOX, self.getHeatmapOptions)
# Smoothing line (S = smoothing line, N = turn off smoothing line) - radiobox
smoothingline_setting = ["On", "Off"]
self.smoothingline_setting_rbox = wx.RadioBox(self, label = "Smoothing Line", pos = (10, 543), choices = smoothingline_setting, style= wx.RA_SPECIFY_ROWS)
self.smoothingline_setting_rbox.SetForegroundColour((255,255,255)) # set text color
self.smoothingline_setting_rbox.Bind(wx.EVT_RADIOBOX, self.getSmoothingLineSetting)
# Test Button
self.test = wx.Button(self, label = "Test", pos = (10, 622), size = (125, 30))
self.test.Bind(wx.EVT_BUTTON, self.getTest)
# Start Button
self.start = wx.Button(self, label = "Start", pos = (10, 657), size = (125, 30))
self.start.Bind(wx.EVT_BUTTON, self.getStart)
# -- Adjustment of the width and height of the image using the user inteface --
#start_height
start_height_label = wx.StaticText(self, label = "Starting Height", pos = (160, 5))
start_height_label.SetForegroundColour((255,255,255)) # set text color
self.start_height_textcontrol = wx.TextCtrl(self, pos = (160, 20), size = (100, 20))
self.start_height_textcontrol.SetValue("0")
self.start_height_textcontrol.Bind(wx.EVT_TEXT, self.getStartHeight)
#end_height
end_height_label = wx.StaticText(self, label = "Ending Height", pos = (290, 5))
end_height_label.SetForegroundColour((255,255,255)) # set text color
self.end_height_textcontrol = wx.TextCtrl(self, pos = (290, 20), size = (100, 20))
self.end_height_textcontrol.SetValue("500")
self.end_height_textcontrol.Bind(wx.EVT_TEXT, self.getEndHeight)
#start_width
start_width_label = wx.StaticText(self, label = "Starting Width", pos = (420, 5))
start_width_label.SetForegroundColour((255,255,255)) # set text color
self.start_width_textcontrol = wx.TextCtrl(self, pos = (420, 20), size = (100, 20))
self.start_width_textcontrol.SetValue("0")
self.start_width_textcontrol.Bind(wx.EVT_TEXT, self.getStartWidth)
#end_width
end_width_label = wx.StaticText(self, label = "Ending Width", pos = (550, 5))
end_width_label.SetForegroundColour((255,255,255)) # set text color
self.end_width_textcontrol = wx.TextCtrl(self, pos = (550, 20), size = (100, 20))
self.end_width_textcontrol.SetValue("1000")
self.end_width_textcontrol.Bind(wx.EVT_TEXT, self.getEndWidth)
def getImageList(self, event):
dlg = wx.DirDialog(self, message="Choose a folder")
self.imgs = []
if dlg.ShowModal() == wx.ID_OK:
self.dirname = dlg.GetPath()
if os.path.isdir(self.dirname):
for y in sorted(os.listdir(self.dirname)):
if y.endswith(".TIFF"):
self.imgs.append(os.path.join(self.dirname, y))
if len(self.imgs) >= 2:
toshow = round(len(self.imgs) / 2)
else:
toshow = 0
png = wx.Image(self.imgs[toshow], wx.BITMAP_TYPE_ANY)
self.W, self.H = png.GetSize()
png = png.Scale(500, 500).ConvertToBitmap()
self.bitmap = wx.StaticBitmap(self, -1, png, (160, 50), (png.GetWidth(), png.GetHeight()))
dlg.Destroy()
def getStartingImage(self, event):
self.starting_image_number = self.starting_image_number_spin.GetValue()
png = wx.Image(self.imgs[self.starting_image_number], wx.BITMAP_TYPE_ANY)
png = png.Scale(500, 500).ConvertToBitmap()
self.bitmap.SetBitmap(wx.Bitmap(png))
def getEndingImage(self, event):
self.ending_image_number = self.ending_image_number_spin.GetValue()
def getWhiteThreshold(self, event):
self.white_value_threshold = self.white_value_threshold_spin.GetValue()
def getMinimumGapValue(self, event):
self.minimum_gap_value = -self.minimum_gap_value_spin.GetValue()
def getMaximumGapValue(self, event):
self.maximum_gap_value = -self.maximum_gap_value_spin.GetValue()
def getMinValue(self, event):
self.min_gap_value = self.min_gap_value_spin.GetValue()
def getStorageType(self, event):
self.storage_type = self.storage_type_rbox.GetStringSelection()
def getHeatmapSetting(self, event):
self.heatmap_setting = str(self.heatmap_setting_textcontrol.GetValue())
def getHeatmapOptions(self, event):
self.heatmap_options = event.GetString()
self.heatmap_selector_label_combobox.SetLabel(self.heatmap_options)
def getSmoothingLineSetting(self, event):
self.smoothingline_setting = self.smoothingline_setting_rbox.GetStringSelection()
# Height
def getStartHeight(self, enent):
self.start_height = self.start_height_textcontrol.GetValue()
def getEndHeight(self, enent):
self.end_height = self.end_height_textcontrol.GetValue()
# Width
def getStartWidth(self, event):
self.start_width = self.start_width_textcontrol.GetValue()
def getEndWidth(self, event):
self.end_width = self.end_width_textcontrol.GetValue()
def getTest(self, event):
self.starting_image_number = self.starting_image_number_spin.GetValue()
self.white_value_threshold = self.white_value_threshold_spin.GetValue()
self.minimum_gap_value = -self.minimum_gap_value_spin.GetValue()
self.maximum_gap_value = -self.maximum_gap_value_spin.GetValue()
self.min_gap_value = self.min_gap_value_spin.GetValue()
self.storage_type = self.storage_type_rbox.GetStringSelection()
self.heatmap_setting = str(self.heatmap_setting_textcontrol.GetValue())
self.smoothingline_setting = self.smoothingline_setting_rbox.GetStringSelection()
testing = True
# height and width
self.start_height = self.start_height_textcontrol.GetValue()
self.end_height = self.end_height_textcontrol.GetValue()
if int(self.end_height) > self.H:
self.end_height = self.H
self.end_height_textcontrol.SetValue(str(self.H))
self.start_width = self.start_width_textcontrol.GetValue()
self.end_width = self.end_width_textcontrol.GetValue()
if int(self.end_width) > self.W:
self.end_width = self.W
self.end_width_textcontrol.SetValue(str(self.W))
#Image
image = Image(self.imgs, self.starting_image_number, self.starting_image_number + 1, self.white_value_threshold, self.minimum_gap_value, self.maximum_gap_value, self.min_gap_value, self.storage_type, self.heatmap_setting, self.smoothingline_setting, testing, self.start_height, self.end_height, self.start_width, self.end_width, self.dirname)
image.Scheduler()
def getStart(self, event):
self.starting_image_number = self.starting_image_number_spin.GetValue()
self.ending_image_number = self.ending_image_number_spin.GetValue()
if self.ending_image_number > len(self.imgs):
self.ending_image_number = len(self.imgs)
self.ending_image_number_spin.SetValue(len(self.imgs))
self.white_value_threshold = self.white_value_threshold_spin.GetValue()
self.minimum_gap_value = -self.minimum_gap_value_spin.GetValue()
self.maximum_gap_value = -self.maximum_gap_value_spin.GetValue()
self.min_gap_value = self.min_gap_value_spin.GetValue()
self.storage_type = self.storage_type_rbox.GetStringSelection()
self.heatmap_setting = str(self.heatmap_setting_textcontrol.GetValue())
self.smoothingline_setting = self.smoothingline_setting_rbox.GetStringSelection()
testing = False
# height and width
self.start_height = self.start_height_textcontrol.GetValue()
self.end_height = self.end_height_textcontrol.GetValue()
if int(self.end_height) > self.H:
self.end_height = self.H
self.end_height_textcontrol.SetValue(str(self.H))
self.start_width = self.start_width_textcontrol.GetValue()
self.end_width = self.end_width_textcontrol.GetValue()
if int(self.end_width) > self.W:
self.end_width = self.W
self.end_width_textcontrol.SetValue(str(self.W))
#Image
image = Image(self.imgs, self.starting_image_number, self.ending_image_number, self.white_value_threshold, self.minimum_gap_value, self.maximum_gap_value, self.min_gap_value, self.storage_type, self.heatmap_setting, self.smoothingline_setting, testing, self.start_height, self.end_height, self.start_width, self.end_width, self.dirname)
image.Scheduler()
#Heatmap
retinal_thickness = image.getRetinalThickness()
retinal_thickness_gaps = image.getRetinalThicknessGaps()
name = image.getName()
frame = image.getFrameList()
heat = image.getHeat()
dirname = image.getdirname()
image_list = image.getimagedict()
max = image.getdisplaymax()
min = image.getdisplaymin()
# self.heatmap_options
retinalMap = HeatMap(retinal_thickness, name, frame, heat, retinal_thickness_gaps, dirname, image_list, max, min, self.heatmap_options)
retinalMap.sceduler()
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(parent = None, title = "Automated SD-OCT By: Kent Barter")
self.frame.Show() # Show has to be capital letter
return True # C++ conventionl
app = MyApp()
app.MainLoop()