forked from jamieboss/R21-doppler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguis.py
188 lines (157 loc) · 8.41 KB
/
guis.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
##########################################################################
# Author: Jamie Bossenbroek
# Date: 7/12/19
#
# This function contains the GUI selection tools used in the cbf.py program:
# Method(): the user chooses their method of analysis
# DataEntry(): the user inputs probe angle, max velocity, and min and max probe penetration
# ScrollTest(): check if the automated doppler envelope is acceptable
#
##########################################################################
import tkinter, cv2, vevoAVIparser
from PIL import Image, ImageTk
class Method():
def __init__(self, master):
self.master = master
master.title("Choose Method of Analysis")
#Set window size and position
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
self.master.geometry("320x100+%d+%d" % (screen_width/2-160, screen_height/4))
#Buttons for method selection
tkinter.Button(master, text = "Doppler Flow Pattern Analysis", command = self.choice1).pack()
master.bind('d', self.choice1) #Bind key to button
tkinter.Button(master, text = "Combined Analysis", command = self.choice2).pack()
master.bind('c', self.choice2) #Bind key to button
#String variable to store and display choice
self.choice = ''
self.labelText = tkinter.StringVar()
self.labelText.set('Selection: ')
tkinter.Label(master, textvariable = self.labelText).pack()
#Save choice and exit
tkinter.Button(master, text = "Save", command = self.end).pack()
master.bind('<Return>', self.end) #Bind enter key to button
def choice1(self, _event=None):
self.choice = 'Doppler Flow Pattern Analysis'
self.labelText.set('Selection: ' + self.choice)
def choice2(self, _event=None):
self.choice = 'Combined Analysis'
self.labelText.set('Selection: ' + self.choice)
def end(self, _event=None):
self.master.destroy()
class DataEntryOne():
def __init__(self, master, bl, hyp):
self.master = master
self.bl = bl
self.hyp = hyp
master.title("Input Parameters")
self.VAngleG = []
self.Max_Pen = []
self.Min_Pen = []
#Screen and picture size
screen_width = master.winfo_screenwidth()
pic_width = int(3*screen_width/7)
pic_height = int(pic_width/1.5)
#Display first image from bl doppler file
image = vevoAVIparser.firstImage(bl)
imageBL = Image.fromarray(image)
imageBL = imageBL.resize((pic_width, pic_height), Image.ANTIALIAS)
self.dispBL = ImageTk.PhotoImage(imageBL)
self.ArtworkBL = tkinter.Label(master, image = self.dispBL)
self.ArtworkBL.photo = self.dispBL
tkinter.Label(master, text = "Colormode Values", font = 'Helvetica 18 bold').grid(row = 0, columnspan = 4)
self.ArtworkBL.grid(row = 1, column=0, columnspan=2)
tkinter.Label(master, text = "Angle of Probe from Verticle (degrees):").grid(row = 2)
self.e1 = tkinter.Entry(master)
self.e1.grid(row = 2, column = 1)
tkinter.Label(master, text = "Max Penetration Depth (mm):").grid(row = 3)
self.e2 = tkinter.Entry(master)
self.e2.grid(row = 3, column = 1)
tkinter.Label(master, text = "Min Penetration Depth (mm):").grid(row = 4)
self.e3 = tkinter.Entry(master)
self.e3.grid(row = 4, column = 1)
#Display first image from hyperemia doppler file
image2 = vevoAVIparser.firstImage(hyp)
imageH = Image.fromarray(image2)
imageH = imageH.resize((pic_width, pic_height), Image.ANTIALIAS)
self.dispH = ImageTk.PhotoImage(imageH)
self.ArtworkH = tkinter.Label(master, image = self.dispH)
self.ArtworkH.photo = self.dispH
self.ArtworkH.grid(row = 1, column =2, columnspan = 2)
tkinter.Label(master, text = "Angle of Probe from Verticle (degrees):").grid(row = 2, column = 2)
self.e4 = tkinter.Entry(master)
self.e4.grid(row = 2, column = 3)
tkinter.Label(master, text = "Max Penetration Depth (mm):").grid(row = 3, column = 2)
self.e5 = tkinter.Entry(master)
self.e5.grid(row = 3, column = 3)
tkinter.Label(master, text = "Min Penetration Depth (mm):").grid(row = 4, column = 2)
self.e6 = tkinter.Entry(master)
self.e6.grid(row = 4, column = 3)
#Return input values and exit
tkinter.Button(master, text = "Enter", command = self.get_values, height = 5, width = 20).grid(row = 5, column = 3)
master.bind('<Return>', self.get_values) #Bind enter key to button
def get_values(self, _event=None):
self.VAngleG.append(self.e1.get())
self.Max_Pen.append(self.e2.get())
self.Min_Pen.append(self.e3.get())
self.VAngleG.append(self.e4.get())
self.Max_Pen.append(self.e5.get())
self.Min_Pen.append(self.e6.get())
self.master.destroy()
class ScrollTest():
def __init__(self, master, automaticThreshold, otsuImage, blurredImage):
self.master = master
master.title("Scroll Test")
self.blurredImage = blurredImage
self.automaticThresh = automaticThreshold
self.threshold = automaticThreshold
#Set window position and picture size
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
self.pic_width = int(screen_width * .9)
self.pic_height = int(self.pic_width * len(otsuImage)/len(otsuImage[0]))
self.master.geometry("+%d+%d" % (screen_width/2-self.pic_width/2, screen_height/4))
tkinter.Label(master, text = "Proceed with automated threshold or threshold image manually?").grid(row = 0, columnspan = 2)
#Automatic threshold
tkinter.Button(master, text = "Use Automatic Threshold", command = self.automatic).grid(row = 1, columnspan = 2)
tkinter.Label(master, text = "Automatic Threshold: " + str(self.automaticThresh)).grid(row = 2, columnspan = 2)
master.bind('<Return>', self.automatic) #Bind enter key to button
otsuImage = Image.fromarray(otsuImage)
otsuImage = otsuImage.resize((self.pic_width, self.pic_height), Image.ANTIALIAS)
self.otsu = ImageTk.PhotoImage(otsuImage)
self.Artwork = tkinter.Label(master, image = self.otsu)
self.Artwork.photo = self.otsu
self.Artwork.grid(row = 3, columnspan = 2)
#Manual threshold
tkinter.Button(master, text = "Use Manual Threshold", command = self.manual).grid(row = 4, columnspan = 2)
self.labelText = tkinter.StringVar()
self.labelText.set('Manual threshold: ' + str(self.threshold))
tkinter.Label(master, textvariable = self.labelText).grid(row = 5, columnspan = 2)
#Increase or decrease threshold
tkinter.Button(master, text = "+", command = self.increase, height = 2, width = 5).grid(row = 6, column = 1)
master.bind('+', self.increase)
tkinter.Button(master, text = "-", command = self.decrease, height = 2, width = 5).grid(row = 6, column = 0)
master.bind('-', self.decrease)
#Display manual threshold
tkinter.Button(master, text="Display manual threshold", command = self.manualImage).grid(row = 7, columnspan = 2)
master.bind('<space>', self.manualImage)
def increase(self, _event=None):
self.threshold += 1
self.labelText.set('Manual threshold: ' + str(self.threshold))
def decrease(self, _event=None):
self.threshold -= 1
self.labelText.set('Manual threshold: ' + str(self.threshold))
def manualImage(self, _event=None):
#Manual threshold image
thresh, img = cv2.threshold(self.blurredImage, self.threshold, 255, cv2.THRESH_BINARY)
img = Image.fromarray(img)
img = img.resize((self.pic_width, self.pic_height), Image.ANTIALIAS)
self.manualImage = ImageTk.PhotoImage(img)
self.ArtworkM = tkinter.Label(self.master, image = self.manualImage)
self.ArtworkM.photo = self.manualImage
self.ArtworkM.grid(row = 8, columnspan = 2)
def automatic(self, _event=None):
self.threshold = self.automaticThresh
self.master.destroy()
def manual(self, _event=None):
self.master.destroy()