@@ -844,22 +844,7 @@ def color(image: tf.Tensor, factor: float) -> tf.Tensor:
844
844
845
845
def contrast (image : tf .Tensor , factor : float ) -> tf .Tensor :
846
846
"""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 )
863
848
864
849
865
850
def brightness (image : tf .Tensor , factor : float ) -> tf .Tensor :
0 commit comments