-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilterFrame.py
107 lines (78 loc) · 3.66 KB
/
filterFrame.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
from tkinter import Toplevel,Button,RIGHT
import numpy as np
import cv2
class FilterFrame(Toplevel):
def __init__(self,master=None):
Toplevel.__init__(self,master=master)
self.original_image = self.master.processed_image
self.filtered_image = None
self.negative_button = Button(master=self,text="Negative")
self.black_white_button = Button(master=self,text="Black White")
self.sepia_button = Button(master=self,text="Sepia")
self.embross_button = Button(master=self,text="Embross")
self.gaussian_blur_button = Button(master=self,text="Gaussian Blur")
self.median_blur_button = Button(master=self,text="Median Blur")
self.cancel_button = Button(master=self,text="Cancel")
self.apply_button = Button(master=self,text="Apply")
self.negative_button.bind("<ButtonRelease>",self.negative_button_released)
self.black_white_button.bind("<ButtonRelease>",self.black_white_released)
self.sepia_button.bind("<ButtonRelease>",self.sepia_button_released)
self.embross_button.bind("<ButtonRelease>",self.embross_button_released)
self.gaussian_blur_button.bind("<ButtonRelease>",self.gaussian_blur_button_released)
self.median_blur_button.bind("<ButtonRelease>",self.median_blur_button_released)
self.apply_button.bind("<ButtonRelease>",self.apply_button_released)
self.cancel_button.bind("<ButtonRelease>",self.cancel_button_released)
self.negative_button.pack()
self.black_white_button.pack()
self.sepia_button.pack()
self.embross_button.pack()
self.gaussian_blur_button.pack()
self.median_blur_button.pack()
self.cancel_button.pack(side=RIGHT)
self.apply_button.pack()
def negative_button_released(self,event):
self.negative()
self.show_image()
def black_white_released(self,event):
self.black_white()
self.show_image()
def sepia_button_released(self,event):
self.sepia()
self.show_image()
def embross_button_released(self,event):
self.embross()
self.show_image()
def gaussian_blur_button_released(self,event):
self.gaussian_blur()
self.show_image()
def median_blur_button_released(self,event):
self.median_blur()
self.show_image()
def apply_button_released(self,event):
self.master.processed_image = self.filtered_image
self.show_image()
self.close()
def cancel_button_released(self,event):
self.master.image_viewer.show_image()
self.close()
def show_image(self):
self.master.image_viewer.show_image(img=self.filtered_image)
def negative(self):
self.filtered_image = cv2.bitwise_not(self.original_image)
def black_white(self):
self.filtered_image = cv2.cvtColor(self.original_image,cv2.COLOR_BGR2GRAY)
self.filtered_image = cv2.cvtColor(self.filtered_image,cv2.COLOR_GRAY2BGR)
def sepia(self):
kernel= np.array([[0.272, 0.534, 0.131],[0.349, 0.686, 0.168],[0.393, 0.769, 0.189]])
self.filtered_image = cv2.filter2D(self.original_image,-1,kernel)
def embross(self):
kernel1 = np.array([[0, -1, -1], # kernel for embossing bottom left side
[1, 0, -1],
[1, 1, 0]])
self.filtered_image = cv2.filter2D(self.original_image,-1,kernel1)
def gaussian_blur(self):
self.filtered_image = cv2.GaussianBlur(self.original_image,(41,41),0)
def median_blur(self):
self.filtered_image = cv2.medianBlur(self.original_image,41)
def close(self):
self.destroy()