Skip to content

Commit

Permalink
Merge pull request #11219 from EIFY:fix-contrast
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 712947091
  • Loading branch information
tensorflower-gardener committed Jan 7, 2025
2 parents 103d7d5 + 39e11cd commit 156da80
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions official/vision/ops/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,19 +844,7 @@ def color(image: tf.Tensor, factor: float) -> tf.Tensor:

def contrast(image: tf.Tensor, factor: float) -> tf.Tensor:
"""Equivalent of PIL Contrast."""
degenerate = tf.image.rgb_to_grayscale(image)
# Cast before calling tf.histogram.
degenerate = tf.cast(degenerate, tf.int32)

# Compute the grayscale histogram, then compute the mean pixel value,
# and create a constant image size of that value. Use that as the
# blending degenerate target of the original image.
hist = tf.histogram_fixed_width(degenerate, [0, 255], nbins=256)
mean = tf.reduce_sum(tf.cast(hist, tf.float32)) / 256.0
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)
return tf.image.adjust_contrast(image, factor)


def brightness(image: tf.Tensor, factor: float) -> tf.Tensor:
Expand Down

0 comments on commit 156da80

Please sign in to comment.