-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunsharp_mask
78 lines (60 loc) · 2.28 KB
/
unsharp_mask
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
import cv2
from tkinter import *
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import filedialog
from PIL import Image, ImageTk
class unsharp_highboost:
path = '/home/cloud/Desktop/moon.jpg'
def __init__(self, master):
self.frame1 = Frame(master)
self.frame2 = Frame(master)
hbtn = Button(self.frame2, text="OPEN IMAGE", command=lambda: self.button_click(master))
hbtn.pack(fill="none", expand=True)
self.initUI(master)
def initUI(self, master):
self.frame1.grid(row=0, column=0)
self.frame2.grid(row=7, column=0)
if len(unsharp_highboost.path) > 0:
img = cv2.imread(unsharp_highboost.path)
img = cv2.resize(img, (0, 0), fx=0.25, fy=0.25)
blur = cv2.GaussianBlur(img, (5, 5), 0)
mask = img - blur
k = 2
new_weighted = img + k * mask
fig = Figure(figsize=(8, 8))
a = fig.add_subplot(231)
a.imshow(img, cmap='gray')
a.set_title("Original Image")
b = fig.add_subplot(232)
b.imshow(blur, cmap='gray')
b.set_title("Average Filter - blur")
c = fig.add_subplot(233)
c.imshow(mask, cmap='gray')
c.set_title("Mask")
d = fig.add_subplot(235)
d.imshow(new_weighted, cmap='gray')
d.set_title("k = 2")
k = 0.5
new_weighted = img + k * mask
new_weighted.astype(int)
new_weighted = (new_weighted * 255 / np.max(new_weighted)).astype('uint8')
e = fig.add_subplot(234)
e.imshow(new_weighted, cmap='gray')
e.set_title("k=0.5")
canvas = FigureCanvasTkAgg(fig, self.frame1)
canvas.get_tk_widget().grid(row=1, column=0, columnspan=4, rowspan=8)
canvas.draw()
def button_click(self, master):
unsharp_highboost.path = filedialog.askopenfilename(filetypes=[("Image File", '.jpg')])
self.initUI(master)
def main():
root = Tk()
root.title("Unsharp masking and Highboost filter")
unsharp_highboost(root)
root.mainloop()
if __name__ == '__main__':
main()