Skip to content

Commit 39e11cd

Browse files
committed
just call tf.image.adjust_contrast()
1 parent 7d892a7 commit 39e11cd

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

Diff for: official/vision/ops/augment.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -844,22 +844,7 @@ def color(image: tf.Tensor, factor: float) -> tf.Tensor:
844844

845845
def contrast(image: tf.Tensor, factor: float) -> tf.Tensor:
846846
"""Equivalent of PIL Contrast."""
847-
image_height = tf.shape(image)[0]
848-
image_width = tf.shape(image)[1]
849-
degenerate = tf.image.rgb_to_grayscale(image)
850-
# Cast before calling tf.histogram.
851-
degenerate = tf.cast(degenerate, tf.int32)
852-
853-
# Compute the grayscale histogram, then compute the mean pixel value,
854-
# and create a constant image size of that value. Use that as the
855-
# blending degenerate target of the original image.
856-
hist = tf.histogram_fixed_width(degenerate, [0, 255], nbins=256)
857-
mean = tf.reduce_sum(
858-
tf.cast(hist, tf.float32) * tf.linspace(0., 255., 256)) / float(image_height * image_width)
859-
degenerate = tf.ones_like(degenerate, dtype=tf.float32) * mean
860-
degenerate = tf.clip_by_value(degenerate, 0.0, 255.0)
861-
degenerate = tf.image.grayscale_to_rgb(tf.cast(degenerate, tf.uint8))
862-
return blend(degenerate, image, factor)
847+
return tf.image.adjust_contrast(image, factor)
863848

864849

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

0 commit comments

Comments
 (0)