def get_masks(origin_images, height, width, channels=3):
"""add horizon color lines and set empty"""
quarty = tf.random_uniform([height/4, 1])
prop = tf.scalar_mul(tf.convert_to_tensor(0.2), tf.ones([height/4, 1]))
quarty = tf.round(tf.add(quarty, prop))
y = tf.reshape(tf.stack([quarty, quarty, quarty, quarty], axis=1), [height, 1])
mask = tf.matmul(y, tf.ones([1, width]))
masks = tf.expand_dims(mask, 0)
masks = tf.expand_dims(masks, -1)
maskedimages = tf.mul(origin_images, masks)
"""add noise"""
scale = tf.random_uniform([channels, height, 1])
y = tf.subtract(tf.ones([height, 1]), y)
y = tf.expand_dims(y, 0)
y = tf.scalar_mul(tf.convert_to_tensor(255.), tf.multiply(scale, y))
noise = tf.add(mask, tf.matmul(y, tf.ones([channels, 1, width])))
noise = tf.pack(tf.split(value=noise, num_or_size_splits=noise.get_shape()[0], axis=0), axis=3)
maskedimages = tf.add(maskedimages, noise)
return maskedimages
评论列表
文章目录