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
| def all_yuv_tur(image_in, ratio=1.0):
def yuv_tur(image , case): image = image / 255 image = tf.image.rgb_to_yuv(image) yuv_channels = tf.split(image, 3, 2) y = yuv_channels[0] uv = tf.concat(yuv_channels[1:],2) shape1 = uv.get_shape().as_list() level=int(8*ratio)
d1 = tf.random_uniform([], maxval=level, dtype=tf.int32) d2 = tf.random_uniform([], maxval=level, dtype=tf.int32)
if case == 0: uv = tf.slice(uv, [0,0,0], [shape1[0]-d1, shape1[1]-d2, shape1[2]]) uv = tf.pad(uv, [[d1,0], [d2, 0], [0,0]]) elif case == 1: uv = tf.slice(uv, [d1,d2,0], [shape1[0]-d1, shape1[1]-d2, shape1[2]]) uv = tf.pad(uv, [[0, d1], [0, d2], [0,0]]) elif case == 2: uv = tf.slice(uv, [d1,0,0], [shape1[0]- d1, shape1[1]-d2, shape1[2]]) uv = tf.pad(uv, [[0, d1], [d2, 0], [0,0]]) elif case == 3: uv = tf.slice(uv, [0,d2,0], [shape1[0]-d1, shape1[1]-d2, shape1[2]]) uv = tf.pad(uv, [[d1, 0], [0, d2], [0,0]])
yuv_image = tf.concat([y, uv], 2) image = tf.image.yuv_to_rgb(yuv_image) image = image * 255 return image
def yuv_tur_sel(image): image = apply_with_random_selector(image, lambda x, ordering: yuv_tur(x, ordering), num_cases=4) return image
ran = tf.random_uniform([]) image = tf.cond(ran<0.1, lambda: yuv_tur_sel(image_in), lambda: image_in) return image
|