def contrast(image, factor):
    'Equivalent of PIL Contrast.'
    grayscale_im = tf.image.rgb_to_grayscale(image)
    mean = tf.reduce_mean(tf.cast(grayscale_im, tf.float32))
    mean = tf.saturate_cast((mean + 0.5), tf.uint8)
    degenerate = (tf.ones_like(grayscale_im, dtype=tf.uint8) * mean)
    degenerate = tf.image.grayscale_to_rgb(degenerate)
    return blend(degenerate, image, factor)
Equivalent of PIL Contrast.
def contrast(image, factor):
    
    grayscale_im = tf.image.rgb_to_grayscale(image)
    mean = tf.reduce_mean(tf.cast(grayscale_im, tf.float32))
    mean = tf.saturate_cast((mean + 0.5), tf.uint8)
    degenerate = (tf.ones_like(grayscale_im, dtype=tf.uint8) * mean)
    degenerate = tf.image.grayscale_to_rgb(degenerate)
    return blend(degenerate, image, factor)