MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / adjust_jpeg_quality

Function adjust_jpeg_quality

tensorflow/python/ops/image_ops_impl.py:2009–2055  ·  view source on GitHub ↗

Adjust jpeg encoding quality of an RGB image. This is a convenience method that adjusts jpeg encoding quality of an RGB image. `image` is an RGB image. The image's encoding quality is adjusted to `jpeg_quality`. `jpeg_quality` must be in the interval `[0, 100]`. Args: image: RGB

(image, jpeg_quality, name=None)

Source from the content-addressed store, hash-verified

2007
2008@tf_export('image.adjust_jpeg_quality')
2009def adjust_jpeg_quality(image, jpeg_quality, name=None):
2010 """Adjust jpeg encoding quality of an RGB image.
2011
2012 This is a convenience method that adjusts jpeg encoding quality of an
2013 RGB image.
2014
2015 `image` is an RGB image. The image's encoding quality is adjusted
2016 to `jpeg_quality`.
2017 `jpeg_quality` must be in the interval `[0, 100]`.
2018
2019 Args:
2020 image: RGB image or images. Size of the last dimension must be 3.
2021 jpeg_quality: Python int or Tensor of type int32. jpeg encoding quality.
2022 name: A name for this operation (optional).
2023
2024 Returns:
2025 Adjusted image(s), same shape and DType as `image`.
2026
2027 Usage Example:
2028 ```python
2029 >> import tensorflow as tf
2030 >> x = tf.random.normal(shape=(256, 256, 3))
2031 >> tf.image.adjust_jpeg_quality(x, 75)
2032 ```
2033 Raises:
2034 InvalidArgumentError: quality must be in [0,100]
2035 InvalidArgumentError: image must have 1 or 3 channels
2036 """
2037 with ops.name_scope(name, 'adjust_jpeg_quality', [image]) as name:
2038 image = ops.convert_to_tensor(image, name='image')
2039 # Remember original dtype to so we can convert back if needed
2040 orig_dtype = image.dtype
2041 # Convert to uint8
2042 image = convert_image_dtype(image, dtypes.uint8)
2043 # Encode image to jpeg with given jpeg quality
2044 if compat.forward_compatible(2019, 4, 4):
2045 if not _is_tensor(jpeg_quality):
2046 # If jpeg_quality is a int (not tensor).
2047 jpeg_quality = ops.convert_to_tensor(jpeg_quality, dtype=dtypes.int32)
2048 image = gen_image_ops.encode_jpeg_variable_quality(image, jpeg_quality)
2049 else:
2050 image = gen_image_ops.encode_jpeg(image, quality=jpeg_quality)
2051
2052 # Decode jpeg image
2053 image = gen_image_ops.decode_jpeg(image)
2054 # Convert back to original dtype and return
2055 return convert_image_dtype(image, orig_dtype)
2056
2057
2058@tf_export('image.random_saturation')

Callers 1

random_jpeg_qualityFunction · 0.85

Calls 4

convert_image_dtypeFunction · 0.85
decode_jpegMethod · 0.80
_is_tensorFunction · 0.70
name_scopeMethod · 0.45

Tested by

no test coverage detected