-
Notifications
You must be signed in to change notification settings - Fork 0
/
guiNew.py
60 lines (42 loc) · 1.27 KB
/
guiNew.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
from tkinter import *
from tkinter.ttk import *
from tkinter import filedialog
from PIL import Image
from PIL import ImageTk
import cv2
def initialize():
root = Tk()
root.title("DIP app")
root.geometry('1280x820')
return root
def labels(rt):
w = Label(rt, text='Apply filters', font=("Arial", 25))
w.pack()
def buttons(rt):
b2 = Button(rt, text='Select Image', command=selectImage)
b2.place(relx=0.5, rely=0.5, anchor=CENTER)
return b2
def selectImage():
path = filedialog.askopenfilename()
if len(path) > 0:
image = cv2.imread(path)
# computations for resizing
height = len(image)
width = len(image[0])
a = height / 700
width = int(width / a)
height = 700
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
image = image.resize((width, height), Image.ANTIALIAS)
image = ImageTk.PhotoImage(image)
frameImage_Options(image, height, width)
def frameImage_Options(img, h, w):
canvas = Canvas(root, width=w, height=h)
canvas.create_image(10, 10, anchor=NW, image=img)
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
canvas.mainloop()
root = initialize()
labels(root)
b2 = buttons(root)
root.mainloop()