-
Notifications
You must be signed in to change notification settings - Fork 27
/
gui.py
112 lines (85 loc) · 3.84 KB
/
gui.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
import tkinter
from PIL import Image
from tkinter import filedialog
import cv2 as cv
from frames import *
from displayTumor import *
from predictTumor import *
class Gui:
MainWindow = 0
listOfWinFrame = list()
FirstFrame = object()
val = 0
fileName = 0
DT = object()
wHeight = 700
wWidth = 1180
def __init__(self):
global MainWindow
MainWindow = tkinter.Tk()
MainWindow.geometry('1200x720')
MainWindow.resizable(width=False, height=False)
self.DT = DisplayTumor()
self.fileName = tkinter.StringVar()
self.FirstFrame = Frames(self, MainWindow, self.wWidth, self.wHeight, 0, 0)
self.FirstFrame.btnView['state'] = 'disable'
self.listOfWinFrame.append(self.FirstFrame)
WindowLabel = tkinter.Label(self.FirstFrame.getFrames(), text="Brain Tumor Detection", height=1, width=40)
WindowLabel.place(x=320, y=30)
WindowLabel.configure(background="White", font=("Comic Sans MS", 16, "bold"))
self.val = tkinter.IntVar()
RB1 = tkinter.Radiobutton(self.FirstFrame.getFrames(), text="Detect Tumor", variable=self.val,
value=1, command=self.check)
RB1.place(x=250, y=200)
RB2 = tkinter.Radiobutton(self.FirstFrame.getFrames(), text="View Tumor Region",
variable=self.val, value=2, command=self.check)
RB2.place(x=250, y=250)
browseBtn = tkinter.Button(self.FirstFrame.getFrames(), text="Browse", width=8, command=self.browseWindow)
browseBtn.place(x=800, y=550)
MainWindow.mainloop()
def getListOfWinFrame(self):
return self.listOfWinFrame
def browseWindow(self):
global mriImage
FILEOPENOPTIONS = dict(defaultextension='*.*',
filetypes=[('jpg', '*.jpg'), ('png', '*.png'), ('jpeg', '*.jpeg'), ('All Files', '*.*')])
self.fileName = filedialog.askopenfilename(**FILEOPENOPTIONS)
image = Image.open(self.fileName)
imageName = str(self.fileName)
mriImage = cv.imread(imageName, 1)
self.listOfWinFrame[0].readImage(image)
self.listOfWinFrame[0].displayImage()
self.DT.readImage(image)
def check(self):
global mriImage
#print(mriImage)
if (self.val.get() == 1):
self.listOfWinFrame = 0
self.listOfWinFrame = list()
self.listOfWinFrame.append(self.FirstFrame)
self.listOfWinFrame[0].setCallObject(self.DT)
res = predictTumor(mriImage)
if res > 0.5:
resLabel = tkinter.Label(self.FirstFrame.getFrames(), text="Tumor Detected", height=1, width=20)
resLabel.configure(background="White", font=("Comic Sans MS", 16, "bold"), fg="red")
else:
resLabel = tkinter.Label(self.FirstFrame.getFrames(), text="No Tumor", height=1, width=20)
resLabel.configure(background="White", font=("Comic Sans MS", 16, "bold"), fg="green")
resLabel.place(x=700, y=450)
elif (self.val.get() == 2):
self.listOfWinFrame = 0
self.listOfWinFrame = list()
self.listOfWinFrame.append(self.FirstFrame)
self.listOfWinFrame[0].setCallObject(self.DT)
self.listOfWinFrame[0].setMethod(self.DT.removeNoise)
secFrame = Frames(self, MainWindow, self.wWidth, self.wHeight, self.DT.displayTumor, self.DT)
self.listOfWinFrame.append(secFrame)
for i in range(len(self.listOfWinFrame)):
if (i != 0):
self.listOfWinFrame[i].hide()
self.listOfWinFrame[0].unhide()
if (len(self.listOfWinFrame) > 1):
self.listOfWinFrame[0].btnView['state'] = 'active'
else:
print("Not Working")
mainObj = Gui()