-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·160 lines (139 loc) · 5.55 KB
/
Copy pathmain.py
File metadata and controls
executable file
·160 lines (139 loc) · 5.55 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from layouting import *
from histogram import *
import os.path
from PIL import Image
from processing_list import *
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == "folder_images":
folder = values["folder_images"]
try:
list_file = os.listdir(folder)
except:
list_file = []
file_name = [
f
for f in list_file
if os.path.isfile(os.path.join(folder, f))
and f.lower().endswith((".png", ".gif"))
]
window["list_image"].update(file_name)
if event == "list_image":
try:
filename = os.path.join(values["folder_images"], values["list_image"][0])
window["image_path"].update(filename)
window["preview_input_image"].update(filename)
window["type_processing"].update(filename)
window["preview_output_image"].update(filename)
input_image = Image.open(filename)
image_width, image_height = input_image.size
window["image_size"].update(
"Image Size : " + str(image_width) + " x " + str(image_height)
)
mode_to_coldepth = {
"1": 1,
"L": 8,
"P": 8,
"RGB": 24,
"RGBA": 32,
"CMYK": 32,
"YCbCr": 24,
"LAB": 24,
"HSV": 24,
"I": 32,
"F": 32,
}
color_depth = mode_to_coldepth[input_image.mode]
window["image_color_depth"].update("Color Depth : " + str(color_depth))
except:
pass
elif event == " ":
try:
window["cancel"].update(visible=True)
window["type_processing"].update("Image Thresholding")
# Thresholding
window["text_thresholding"].update(visible=True)
window["slider_thresholding"].update(visible=True)
window["submit_thresholding"].update(visible=True)
# Brigthness
window["text_brightness"].update(visible=False)
window["slider_brightness"].update(visible=False)
window["submit_brightness"].update(visible=False)
except:
pass
elif event == "image_negative":
try:
window["cancel"].update(visible=True)
# Thresholding
window["text_thresholding"].update(visible=False)
window["slider_thresholding"].update(visible=False)
window["submit_thresholding"].update(visible=False)
# Brigthness
window["text_brightness"].update(visible=False)
window["slider_brightness"].update(visible=False)
window["submit_brightness"].update(visible=False)
window["type_processing"].update("Image Negative")
output_image = negative(input_image, color_depth)
histogram = calculate_horizontal_histogram(image_input)
output_image.save(filename_out)
window["preview_output_image"].update(filename=filename_out)
window['preview_output_histogram'].update('hallo')
except:
pass
elif event == "image_brigtness":
try:
window["cancel"].update(visible=True)
window["type_processing"].update("Image Brigtness")
# Thresholding
window["text_thresholding"].update(visible=False)
window["slider_thresholding"].update(visible=False)
window["submit_thresholding"].update(visible=False)
# Brigthness
window["text_brightness"].update(visible=True)
window["slider_brightness"].update(visible=True)
window["submit_brightness"].update(visible=True)
except:
pass
elif event == "equalization_greyscale":
try:
window["type_processing"].update("Equalization Greyscale")
output_image.save(filename_out)
window["preview_output_image"].update(filename=filename_out)
except:
pass
elif event == "submit_thresholding":
try:
value = int(values["slider_thresholding"])
output_image = thresholding(input_image, color_depth, value)
output_image.save(filename_out)
window["preview_output_image"].update(filename=filename_out)
except:
pass
elif event == "submit_brightness":
try:
value = int(values["slider_brightness"])
window["type_processing"].update("Image Brightness")
output_image = brightness(input_image, color_depth, value)
output_image.save(filename_out)
window["preview_output_image"].update(filename=filename_out)
except:
pass
elif event == "cancel":
try:
output_image = input_image
output_image.save(filename_out)
window["preview_output_image"].update(filename=filename_out)
window["cancel"].update(visible=False)
window["type_processing"].update("")
# Thresholding
window["text_thresholding"].update(visible=False)
window["slider_thresholding"].update(visible=False)
window["submit_thresholding"].update(visible=False)
# Brigthness
window["text_brightness"].update(visible=False)
window["slider_brightness"].update(visible=False)
window["submit_brightness"].update(visible=False)
except:
pass