-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_image_aug.py
261 lines (210 loc) · 8.26 KB
/
test_image_aug.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
"""
Tryout script allowing user to test with all image augmentation method in one image
python ./test_image_aug.py
"""
from augmentation.affine.flip import *
from augmentation.affine.rotate import rotate
from augmentation.affine.translate import translate
from augmentation.affine.shear import *
from augmentation.frequency.frequency_filter import freq_filter
from augmentation.intensity.invert import invert
from augmentation.intensity.hist_equalization import hist_equalization
from augmentation.intensity.amf import amf
from augmentation.edge_detection.canny_edge import canny
from augmentation.frequency.frequency_filter import *
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
def try_flip_vert():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Flip vertically
fv_img = flip_vertical(origin_img)
cv.imshow("Vertical Flipped Image", fv_img)
print(f"Shape of the augmented image is {fv_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_flip_hori():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Flip horizontally
fh_img = flip_horizontal(origin_img)
cv.imshow("Horizontal Flipped Image", fh_img)
print(f"Shape of the augmented image is {fh_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_rand_rotate():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Rotate image
rt_img = rotate(origin_img, 45, "random")
cv.imshow("Rotational Image", rt_img)
print(f"Shape of the augmented image is {rt_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_translate():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Translation image
trans_img = translate(origin_img)
cv.imshow("Translation Image", trans_img)
print(f"Shape of the augmented image is {trans_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_shear_vert():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Shear image vertically
vshear_img = vertical_shear(origin_img)
cv.imshow("Vertical Sheared Image", vshear_img)
print(f"Shape of the augmented image is {vshear_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_shear_hori():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Shear image horizontally
hshear_img = horizontal_shear(origin_img)
cv.imshow("Horizontal Shear Image", hshear_img)
print(f"Shape of the augmented image is {hshear_img.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_gauss_lpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Gaussian lowpass filter
gauss_lpf = freq_filter(origin_img, 8, 2, "gaussian_lpf")
cv.imshow("Gaussian LPF", gauss_lpf)
print(f"Shape of the augmented image is {gauss_lpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_gauss_hpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Gaussian lowpass filter
gauss_hpf = freq_filter(origin_img, 8, 2, "gaussian_hpf")
cv.imshow("Gaussian HPF", gauss_hpf)
print(f"Shape of the augmented image is {gauss_hpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_ideal_lpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Ideal lowpass filter
ideal_lpf = freq_filter(origin_img, 8, 2, "ideal_lpf")
cv.imshow("Ideal LPF", ideal_lpf)
print(f"Shape of the augmented image is {ideal_lpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_ideal_hpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Ideal lowpass filter
ideal_hpf = freq_filter(origin_img, 8, 2, "ideal_hpf")
cv.imshow("Ideal HPF", ideal_hpf)
print(f"Shape of the augmented image is {ideal_hpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_butterworth_hpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Butterworth highpass filter
butterworth_hpf = freq_filter(origin_img, 8, 2, "butterworth_hpf")
cv.imshow("Butterworth LPF", butterworth_hpf)
print(f"Shape of the augmented image is {butterworth_hpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_butterworth_lpf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Butterworth lowpass filter
butterworth_lpf = freq_filter(origin_img, 8, 2, "butterworth_lpf")
cv.imshow("Butterworth LPF", butterworth_lpf)
print(f"Shape of the augmented image is {butterworth_lpf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_invert():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Invert intensity
invert_im = invert(origin_img)
cv.imshow("Inverted", invert_im)
print(f"Shape of the augmented image is {invert_im.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_hist_eq():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Hist-equalization
hist_eq = hist_equalization(origin_img)
cv.imshow("Hist Equalization", hist_eq)
print(f"Shape of the augmented image is {hist_eq.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_amf():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# AMF
amf_im = amf(origin_img)
cv.imshow("AMF", amf_im)
print(f"Shape of the augmented image is {amf.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
def try_canny_ed():
# Read in image of a girl
origin_img = cv.imread("girl.tif")
cv.imshow("Original", origin_img)
print(f"Shape of the original image is {origin_img.shape}")
# Canny Edge Detection
canny_im = canny(origin_img)
cv.imshow("Canny Edge Detection", np.float64(canny_im))
print(f"Shape of the augmented image is {canny_im.shape}")
cv.waitKey(0)
cv.destroyAllWindows() # Allow to press enter to delete all
if __name__ == "__main__":
try_flip_vert()
# try_flip_hori()
# try_rand_rotate()
# try_translate()
# try_shear_vert()
# try_shear_hori()
# try_gauss_lpf()
# try_gauss_hpf()
# try_ideal_lpf()
# try_ideal_hpf()
# try_butterworth_hpf()
# try_butterworth_lpf()
# try_invert()
# try_hist_eq()
# try_amf()
# try_canny_ed()