-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustFrame.py
77 lines (56 loc) · 2.66 KB
/
adjustFrame.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
from tkinter import Toplevel, Label,Scale,Button,HORIZONTAL,RIGHT
import cv2
class AdjustFrame(Toplevel):
def __init__(self,master=None):
Toplevel.__init__(self,master=master)
self.brightness_value = 0
self.previous_brightness_value = 0
self.original_image = self.master.processed_image
self.processing_image = self.master.processed_image
self.brightness_label = Label(self,text="Brightness")
self.brightness_scale = Scale(self,from_=0,to_=2,length=250,resolution=0.1,orient=HORIZONTAL)
self.r_label = Label(self,text="R")
self.r_scale = Scale(self,from_=-100,to_=100,length=250,resolution=1,orient=HORIZONTAL)
self.g_label = Label(self,text="G")
self.g_scale = Scale(self,from_=-100,to_=100,length=250,resolution=1,orient=HORIZONTAL)
self.b_label = Label(self,text="B")
self.b_scale = Scale(self,from_=100,to_=250,length=250,resolution=1,orient=HORIZONTAL)
self.apply_button = Button(self,text="Apply")
self.preview_button = Button(self,text="Preview")
self.cancel_button = Button(self,text="Cancel")
self.brightness_scale.set(1)
self.apply_button.bind("<ButtonRelease>",self.apply_button_released)
self.preview_button.bind("<ButtonRelease>",self.show_button_released)
self.cancel_button.bind("<ButtonRelease>",self.cancel_button_released)
self.brightness_label.pack()
self.brightness_scale.pack()
self.r_label.pack()
self.r_scale.pack()
self.g_label.pack()
self.g_scale.pack()
self.b_label.pack()
self.b_scale.pack()
self.cancel_button.pack(side=RIGHT)
self.preview_button.pack(side=RIGHT)
self.apply_button.pack()
def apply_button_released(self,event):
self.master.processed_image = self.processing_image
self.close()
def show_button_released(self,event):
self.processing_image = cv2.convertScaleAbs(self.original_image,alpha=self.brightness_scale.get())
b,g,r = cv2.split(self.processing_image)
for b_value in b:
cv2.add(b_value,self.b_scale.get(),b_value)
for g_value in g:
cv2.add(g_value,self.g_scale.get(),g_value)
for r_value in r:
cv2.add(r_value,self.r_scale.get(),r_value)
self.processing_image = cv2.merge((b,g,r))
self.show_image(self.processing_image)
def cancel_button_released(self,event):
self.close()
def show_image(self,img=None):
self.master.image_viewer.show_image(img=img)
def close(self):
self.show_image()
self.destroy()