def rgb2yuv(rgb):
"""
Convert RGB image into YUV https://en.wikipedia.org/wiki/YUV
"""
rgb2yuv_filter = tf.constant([[[[0.299, -0.169,
0.499], [0.587, -0.331, -0.418],
[0.114, 0.499, -0.0813]]]])
rgb2yuv_bias = tf.constant([0., 0.5, 0.5])
rgb = tf.expand_dims(rgb, 0)
temp = tf.nn.conv2d(rgb, rgb2yuv_filter, [1, 1, 1, 1], 'SAME')
temp = tf.nn.bias_add(temp, rgb2yuv_bias)
temp = tf.squeeze(temp, [0])
return temp
# Adapted from
# https://github.com/pavelgonchar/colornet/blob/master/train.py
评论列表
文章目录