< Tensorflow >Tensorflow Data Augmentation RGB distortation

This method could augment images by disturbing the RGB value of a image randomly.

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
  def all_color_channel_tur(image):

color_range = 30
def add_color_mask_test(image):
img_shape = image.get_shape().as_list()
img_shape = [img_shape[0], img_shape[1], 1]
ran_color_range_0 = tf.random_uniform([], minval=-color_range, maxval=color_range,dtype=tf.float32)
color_mask_0 = tf.ones(img_shape, dtype = tf.float32) * ran_color_range_0
ran_color_range_1 = tf.random_uniform([], minval=-color_range, maxval=color_range,dtype=tf.float32)
color_mask_1 = tf.ones(img_shape, dtype = tf.float32) * ran_color_range_1

ran_color_range_2 = tf.random_uniform([], minval=-color_range, maxval=color_range,dtype=tf.float32)
color_mask_2 = tf.ones(img_shape, dtype = tf.float32) * ran_color_range_2
sep_channels = tf.split(image, 3, 2)
sep_channels[0] = tf.add(sep_channels[0], color_mask_0)
sep_channels[1] = tf.add(sep_channels[1], color_mask_1)
sep_channels[2] = tf.add(sep_channels[2], color_mask_2)
image = tf.concat(sep_channels,2)
return image

# ran = tf.random_uniform([])
# image = tf.cond(ran<0.5, lambda:add_color_mask_test(image), lambda: image)

image = add_color_mask_test(image)
return image

The images below are original and transfered images:



< Tensorflow >Tensorflow Data Augmentation RGB distortation

https://zhengtq.github.io/2018/12/22/tf-rgb-disturb/

Author

Billy

Posted on

2018-12-22

Updated on

2021-03-13

Licensed under

Comments