def contrast(image, factor):
    'Equivalent of PIL Contrast.'
    degenerate = tf.image.rgb_to_grayscale(image)
    degenerate = tf.cast(degenerate, tf.int32)
    mean = tf.reduce_mean(tf.cast(degenerate, tf.float32))
    degenerate = (tf.ones_like(degenerate, dtype=tf.float32) * mean)
    degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
    degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
    return blend(degenerate, image, factor)
Equivalent of PIL Contrast.
def contrast(image, factor):
    
    degenerate = tf.image.rgb_to_grayscale(image)
    degenerate = tf.cast(degenerate, tf.int32)
    mean = tf.reduce_mean(tf.cast(degenerate, tf.float32))
    degenerate = (tf.ones_like(degenerate, dtype=tf.float32) * mean)
    degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
    degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
    return blend(degenerate, image, factor)