def scale_channel(channel):
    'Scale the 2D image using the autocontrast rule.'
    lo = tf.cast(tf.reduce_min(channel), tf.float32)
    hi = tf.cast(tf.reduce_max(channel), tf.float32)

    def scale_values(im):
        scale = (255.0 / (hi - lo))
        offset = ((- lo) * scale)
        im = ((tf.cast(im, tf.float32) * scale) + offset)
        return tf.saturate_cast(im, tf.uint8)
    result = tf.cond((hi > lo), (lambda : scale_values(channel)), (lambda : channel))
    return result
Scale the 2D image using the autocontrast rule.
def scale_channel(channel):
    
    lo = tf.cast(tf.reduce_min(channel), tf.float32)
    hi = tf.cast(tf.reduce_max(channel), tf.float32)

    def scale_values(im):
        scale = (255.0 / (hi - lo))
        offset = ((- lo) * scale)
        im = ((tf.cast(im, tf.float32) * scale) + offset)
        return tf.saturate_cast(im, tf.uint8)
    result = tf.cond((hi > lo), (lambda : scale_values(channel)), (lambda : channel))
    return result