MCPcopy Create free account
hub / github.com/apache/singa / color_cast

Function color_cast

python/singa/image_tool.py:148–169  ·  view source on GitHub ↗

Add a random value from [-offset, offset] to each channel

(img, offset)

Source from the content-addressed store, hash-verified

146
147
148def color_cast(img, offset):
149 '''Add a random value from [-offset, offset] to each channel'''
150 x = np.asarray(img, dtype='uint8')
151 x.flags.writeable = True
152 cast_value = [0, 0, 0]
153 for i in range(3):
154 r = random.randint(0, 1)
155 if r:
156 cast_value[i] = random.randint(-offset, offset)
157 for w in range(x.shape[0]):
158 for h in range(x.shape[1]):
159 for c in range(3):
160 if cast_value[c] == 0:
161 continue
162 v = x[w][h][c] + cast_value[c]
163 if v < 0:
164 v = 0
165 if v > 255:
166 v = 255
167 x[w][h][c] = v
168 new_img = Image.fromarray(x.astype('uint8'), 'RGB')
169 return new_img
170
171
172def enhance(img, scale):

Callers 1

color_castMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected