def posterize(image, bits):
    'Equivalent of PIL Posterize.'
    shift = tf.cast((8 - bits), image.dtype)
    return tf.bitwise.left_shift(tf.bitwise.right_shift(image, shift), shift)
Equivalent of PIL Posterize.
def posterize(image, bits):
    
    shift = tf.cast((8 - bits), image.dtype)
    return tf.bitwise.left_shift(tf.bitwise.right_shift(image, shift), shift)