-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_a.py
160 lines (123 loc) · 4.18 KB
/
program_a.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
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
import image
import time
def rgb_to_gray(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = p.getRed()
G = p.getGreen()
B = p.getBlue()
emgGray = (R + G + B)//3
new_pixel = image.Pixel(emgGray, emgGray, emgGray)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('gray.gif')
def negate_img(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = 255-p.getRed()
G = 255-p.getGreen()
B = 255-p.getBlue()
new_pixel = image.Pixel(R, G, B)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('negated.gif')
def filter_out_red(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = 0
G = p.getGreen()
B = p.getBlue()
new_pixel = image.Pixel(R, G, B)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('fRed.gif')
def filter_out_green(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = p.getRed()
G = 0
B = p.getBlue()
new_pixel = image.Pixel(R, G, B)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('fGreen.gif')
def filter_out_blue(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = p.getRed()
G = p.getGreen()
B = 0
new_pixel = image.Pixel(R, G, B)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('fBlue.gif')
def sepia_tone(img: image.Image):
win = image.ImageWin(img.get_width(), img.get_height())
emg = img.copy()
for col in range(emg.get_width()):
for row in range(emg.get_height()):
p = emg.get_pixel(col, row)
R = p.getRed()
G = p.getGreen()
B = p.getBlue()
newR = int(R * 0.393 + G * 0.769 + B * 0.189)
newG = int(R * 0.349 + G * 0.686 + B * 0.168)
newB = int(R * 0.272 + G * 0.534 + B * 0.131)
if newR > 255:
newR = 255
if newG > 255:
newG = 255
if newB > 255:
newB = 255
new_pixel = image.Pixel(newR, newG, newB)
emg.set_pixel(col, row, new_pixel)
emg.draw(win)
win.exit_on_click()
emg.save('sepia.gif')
if __name__ == '__main__':
img_path = 'birdCatchesBee.jpg'
img_path2 = 'taalVolcanoLightning.jpg'
choice_img = input('Which Image? == ')
if choice_img == '1':
temp_path = img_path
elif choice_img == '2':
temp_path = img_path2
else:
temp_path = img_path
print('Shit')
i = image.Image(temp_path)
value = input("input here:\n")
if value == "grayscale":
rgb_to_gray(i)
elif value == "negate":
negate_img(i)
elif value == "filterRed":
filter_out_red(i)
elif value == "filterGreen":
filter_out_green(i)
elif value == "filterBlue":
filter_out_blue(i)
elif value == "sepiaTone":
sepia_tone(i)
else:
print("bhudddddddaaaaaaaa")