forked from Jongchan/DISTORT-AND-RECOVER-CVPR18
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_set.py
239 lines (203 loc) · 5.82 KB
/
action_set.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
from scipy.misc import imread, imresize
import numpy as np
import glob
import skimage.color as color
import math
from PIL import Image
import os
def B_sigmoid_low(rgb, width):
l = rgb[:,:,2]
l_final = sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,2] = l_final
return ret
def B_sigmoid_high(rgb, width):
l = rgb[:,:,2]
l_final = sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,2] = l_final
return ret
def B_inv_sigmoid_low(rgb, width):
l = rgb[:,:,2]
l_final = inv_sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,2] = l_final
return ret
def B_inv_sigmoid_high(rgb, width):
l = rgb[:,:,2]
l_final = inv_sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,2] = l_final
return ret
def G_sigmoid_low(rgb, width):
l = rgb[:,:,1]
l_final = sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,1] = l_final
return ret
def G_sigmoid_high(rgb, width):
l = rgb[:,:,1]
l_final = sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,1] = l_final
return ret
def G_inv_sigmoid_low(rgb, width):
l = rgb[:,:,1]
l_final = inv_sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,1] = l_final
return ret
def G_inv_sigmoid_high(rgb, width):
l = rgb[:,:,1]
l_final = inv_sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,1] = l_final
return ret
def R_sigmoid_low(rgb, width):
l = rgb[:,:,0]
l_final = sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,0] = l_final
return ret
def R_sigmoid_high(rgb, width):
l = rgb[:,:,0]
l_final = sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,0] = l_final
return ret
def R_inv_sigmoid_low(rgb, width):
l = rgb[:,:,0]
l_final = inv_sigmoid_low(l,width)
ret = rgb.copy()
ret[:,:,0] = l_final
return ret
def R_inv_sigmoid_high(rgb, width):
l = rgb[:,:,0]
l_final = inv_sigmoid_high(l,width)
ret = rgb.copy()
ret[:,:,0] = l_final
return ret
def L_sigmoid_low(lab, width):
l = lab[:,:,0]
l=l/100.0
l_final = sigmoid_low(l,width)
lab[:,:,0] = l_final*100.0
return lab
def L_sigmoid_high(lab, width):
l = lab[:,:,0]
l=l/100.0
l_final = sigmoid_high(l,width)
lab[:,:,0] = l_final*100.0
return lab
def L_inv_sigmoid_low(lab, width):
l = lab[:,:,0]
l=l/100.0
l_final = inv_sigmoid_low(l,width)
lab[:,:,0] = l_final*100.0
return lab
def L_inv_sigmoid_high(lab, width):
l = lab[:,:,0]
l=l/100.0
l_final = inv_sigmoid_high(l,width)
lab[:,:,0] = l_final*100.0
return lab
def sigmoid_low(in_channel, width):
#l = lab[:,:,0]
#l=l/100.0
top = 1/(1+math.exp(-width*0.375))
bottom = 1/(1+math.exp(-width*-0.625))
"""
in_channel = in_channel*(top-bottom)+bottom
in_channel = np.clip(in_channel, 0.000001, 0.999999)
"""
#in_final = np.log( np.divide( in_channel, (1-in_channel) ) ) / width + 0.625
in_final = (np.divide(1, (1+np.exp(-width*(in_channel-0.625))))-bottom)/(top-bottom)
#lab[:,:,0] = l_final*100.0
return in_final
def sigmoid_high(in_channel, width):
#l = lab[:,:,0]
#l=l/100.0
top = 1/(1+math.exp(-width*0.625))
bottom = 1/(1+math.exp(-width*-0.375))
"""
print 'top', top
print 'bottom', bottom
print 'in_channel', in_channel
#in_channel = in_channel*(top-bottom)+bottom
print 'in_channel', in_channel
#in_channel = np.clip(in_channel, 0.000001, 0.999999)
"""
#in_final = np.log( np.divide( in_channel, (1-in_channel) ) ) / width + 0.625
in_final = (np.divide(1, (1+np.exp(-width*(in_channel-0.375))))-bottom)/(top-bottom)
#lab[:,:,0] = l_final*100.0
return in_final
def inv_sigmoid_low(in_channel, width):
#l = lab[:,:,0]
#l=l/100.0
top = 1/(1+math.exp(-width*0.375))
bottom = 1/(1+math.exp(-width*-0.625))
in_channel = in_channel*(top-bottom)+bottom
in_channel = np.clip(in_channel, 0.000001, 0.999999)
in_final = np.log( np.divide( in_channel, (1-in_channel) ) ) / width + 0.625
#l_final = (np.divide(1, (1+np.exp(-width*(l-0.5))))-bottom)/(top-bottom)
#lab[:,:,0] = l_final*100.0
return in_final
def inv_sigmoid_high(in_channel, width):
#l = lab[:,:,0]
#l=l/100.0
top = 1/(1+math.exp(-width*0.625))
bottom = 1/(1+math.exp(-width*-0.375))
in_channel = in_channel*(top-bottom)+bottom
in_channel = np.clip(in_channel, 0.000001, 0.999999)
in_final = np.log( np.divide( in_channel, (1-in_channel) ) ) / width + 0.375
#l_final = (np.divide(1, (1+np.exp(-width*(l-0.5))))-bottom)/(top-bottom)
#lab[:,:,0] = l_final*100.0
return in_final
"""
def inv_sigmoid_low(lab, width):
l = lab[:,:,0]
l=l/100.0
top = 1/(1+math.exp(-width*0.375))
bottom = 1/(1+math.exp(-width*-0.625))
l = l*(top-bottom)+bottom
l = np.clip(l, 0.000001, 0.999999)
l_final = np.log( np.divide( l, (1-l) ) ) / width + 0.625
#l_final = (np.divide(1, (1+np.exp(-width*(l-0.5))))-bottom)/(top-bottom)
lab[:,:,0] = l_final*100.0
return lab
def inv_sigmoid_high(lab, width):
l = lab[:,:,0]
l=l/100.0
top = 1/(1+math.exp(-width*0.625))
bottom = 1/(1+math.exp(-width*-0.375))
l = l*(top-bottom)+bottom
l = np.clip(l, 0.000001, 0.999999)
l_final = np.log( np.divide( l, (1-l) ) ) / width + 0.375
#l_final = (np.divide(1, (1+np.exp(-width*(l-0.5))))-bottom)/(top-bottom)
lab[:,:,0] = l_final*100.0
return lab
"""
def contrast(image_rgb, b):
mean = np.mean(image_rgb)
degenerate = np.zeros(image_rgb.shape)+mean
image_rgb = b * image_rgb + (1-b) * degenerate
image_rgb = np.clip(image_rgb,0,1)
return image_rgb
def brightness(image_rgb, b):
degenerate = np.zeros(image_rgb.shape)
image_rgb = b * image_rgb + (1-b) * degenerate
image_rgb = np.clip(image_rgb,0,1)
return image_rgb
def color_saturation(image_rgb, b):
degenerate = image_rgb.mean(axis=2)
image_rgb[:,:,0] = b * image_rgb[:,:,0] + (1-b) * degenerate
image_rgb[:,:,1] = b * image_rgb[:,:,1] + (1-b) * degenerate
image_rgb[:,:,2] = b * image_rgb[:,:,2] + (1-b) * degenerate
image_rgb = np.clip(image_rgb,0,1)
return image_rgb
def white_bal(image_rgb, r,g,b):
image_rgb[:,:,0] = r/255.0 * image_rgb[:,:,0]
image_rgb[:,:,1] = g/255.0 * image_rgb[:,:,1]
image_rgb[:,:,2] = b/255.0 * image_rgb[:,:,2]
image_rgb = np.clip(image_rgb,0,1)
return image_rgb