-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathResize.py
120 lines (87 loc) · 3.74 KB
/
Resize.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
#Resize
import cv2
import numpy as np
for i in range(55):
img_str = './teaching/teaching'+str(i+1)+'.jpg'
img = cv2.imread(img_str)
#Resize(AREA = -, CUBIC = +)
img_resize = cv2.resize(img, (256, 256), interpolation=cv2.INTER_AREA)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_0.jpg', img_resize)
img_RGB = cv2.cvtColor(img_resize, cv2.COLOR_BGR2RGB)#BGR2LAB
#Rotate
W, H, C = img_resize.shape
Rotate_Center = int(W/2), int(H/2)
Rotate_Angle = 30
img_rotate = cv2.getRotationMatrix2D(Rotate_Center, Rotate_Angle, 1)
img_reverse_horizon = cv2.flip(img_resize, 1)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_0_Reverse.jpg', img_reverse_horizon)
for j in range(10):
img_rotate = cv2.getRotationMatrix2D(Rotate_Center, Rotate_Angle*(j+1), 1)
img_rotate_result = cv2.warpAffine(img_resize, img_rotate, (W, H))
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_'+str(30*(j+1))+'.jpg', img_rotate_result)
img_reverse_horizon = cv2.flip(img_rotate_result, 1)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_'+str(30*(j+1))+'_Reverse.jpg', img_reverse_horizon)
'''
img_rotate_result = cv2.warpAffine(img_resize, img_rotate, (W, H))
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_90.jpg', img_rotate_result)
img_reverse_horizon = cv2.flip(img_rotate_result, 0)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_90_Reverse.jpg', img_reverse_horizon)
img_rotate_result = cv2.warpAffine(img_rotate_result, img_rotate, (W, H))
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_180.jpg', img_rotate_result)
img_reverse_horizon = cv2.flip(img_rotate_result, 1)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_180_Reverse.jpg', img_reverse_horizon)
img_rotate_result = cv2.warpAffine(img_rotate_result, img_rotate, (W, H))
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_270.jpg', img_rotate_result)
img_reverse_horizon = cv2.flip(img_rotate_result, 0)
cv2.imwrite('./teaching_result/Resize_'+str(i+1)+'_Rotate_270_Reverse.jpg', img_reverse_horizon)
'''
#Contrast&Brightness
'''
hist, bins = np.histogram(img_resize.flatten(), 256,[0,256])
cdf = hist.cumsum()
cdf_m = np.ma.masked_equal(cdf,0)
cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_m,0).astype('uint8')
img_result = cdf[img_resize]
'''
#CLAHE
'''
lab = cv2.cvtColor(img_resize, cv2.COLOR_BGR2LAB)
lab_planes = cv2.split(lab)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
img_result = clahe.apply(lab_planes[0])
'''
#Reverse
'''
img_revers = cv2.cvtColor(img_resize, cv2.COLOR_BGR2LAB)
img_revers_horizon = cv2.flip(img_revers, 1)
img_revers_vertical = cv2.flip(img_revers, 0)
'''
#Rotate
'''
W, H = img_resize.shape
Rotate_Center = int(W/2), int(H/2)
Rotate_Angle = 90
img_rotate = cv2.getRotaionMatrix2d(Rotate_Center, Rotate_Angle, 1)
img_rotate = cv2.warpAffine(img_RGB, img_rotate, (W, H))
'''
#Ouput
'''
cv2.imshow('Origin', img)
cv2.imshow('Resize', img_result)
'''
#Save
'''
cv2.imwrite('./teaching_result/teaching'+str(i+1)+'.jpg', img_result)
'''
import cv2
import numpy as np
for i in range(51):
img = cv2.imread('./teaching_result2/image'+str(i+1)+'.jpg')
hist, bins = np.histogram(img.flatten(), 256,[0,256])
cdf = hist.cumsum()
cdf_m = np.ma.masked_equal(cdf,0)
cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_m,0).astype('uint8')
img_result = cdf[img]
cv2.imwrite('./teaching_result2/image'+str(i+1)+'.jpg', img_result)