tf.image.adjust_jpeg_quality
Stay organized with collections
Save and categorize content based on your preferences.
Adjust jpeg encoding quality of an image.
tf.image.adjust_jpeg_quality(
image, jpeg_quality, name=None
)
This is a convenience method that converts an image to uint8 representation,
encodes it to jpeg with jpeg_quality
, decodes it, and then converts back
to the original data type.
jpeg_quality
must be in the interval [0, 100]
.
Usage Examples:
x = [[[0.01, 0.02, 0.03],
[0.04, 0.05, 0.06]],
[[0.07, 0.08, 0.09],
[0.10, 0.11, 0.12]]]
x_jpeg = tf.image.adjust_jpeg_quality(x, 75)
x_jpeg.numpy()
array([[[0.00392157, 0.01960784, 0.03137255],
[0.02745098, 0.04313726, 0.05490196]],
[[0.05882353, 0.07450981, 0.08627451],
[0.08235294, 0.09803922, 0.10980393]]], dtype=float32)
Note that floating point values are expected to have values in the range
[0,1) and values outside this range are clipped.
x = [[[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]],
[[7.0, 8.0, 9.0],
[10.0, 11.0, 12.0]]]
tf.image.adjust_jpeg_quality(x, 75)
<tf.Tensor: shape=(2, 2, 3), dtype=float32, numpy=
array([[[1., 1., 1.],
[1., 1., 1.]],
[[1., 1., 1.],
[1., 1., 1.]]], dtype=float32)>
Note that jpeg_quality
100 is still lossy compresson.
x = tf.constant([[[1, 2, 3],
[4, 5, 6]],
[[7, 8, 9],
[10, 11, 12]]], dtype=tf.uint8)
tf.image.adjust_jpeg_quality(x, 100)
<tf.Tensor: shape(2, 2, 3), dtype=uint8, numpy=
array([[[ 0, 1, 3],
[ 3, 4, 6]],
[[ 6, 7, 9],
[ 9, 10, 12]]], dtype=uint8)>
Args |
image
|
3D image. The size of the last dimension must be None, 1 or 3.
|
jpeg_quality
|
Python int or Tensor of type int32. jpeg encoding quality.
|
name
|
A name for this operation (optional).
|
Returns |
Adjusted image, same shape and DType as image .
|
Raises |
InvalidArgumentError
|
quality must be in [0,100]
|
InvalidArgumentError
|
image must have 1 or 3 channels
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-03-23 UTC.
[null,null,["Last updated 2023-03-23 UTC."],[],[],null,["# tf.image.adjust_jpeg_quality\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.11.1/tensorflow/python/ops/image_ops_impl.py#L2901-L2976) |\n\nAdjust jpeg encoding quality of an image.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.image.adjust_jpeg_quality`](https://www.tensorflow.org/api_docs/python/tf/image/adjust_jpeg_quality)\n\n\u003cbr /\u003e\n\n tf.image.adjust_jpeg_quality(\n image, jpeg_quality, name=None\n )\n\nThis is a convenience method that converts an image to uint8 representation,\nencodes it to jpeg with `jpeg_quality`, decodes it, and then converts back\nto the original data type.\n\n`jpeg_quality` must be in the interval `[0, 100]`.\n\n#### Usage Examples:\n\n x = [[[0.01, 0.02, 0.03],\n [0.04, 0.05, 0.06]],\n [[0.07, 0.08, 0.09],\n [0.10, 0.11, 0.12]]]\n x_jpeg = tf.image.adjust_jpeg_quality(x, 75)\n x_jpeg.numpy()\n array([[[0.00392157, 0.01960784, 0.03137255],\n [0.02745098, 0.04313726, 0.05490196]],\n [[0.05882353, 0.07450981, 0.08627451],\n [0.08235294, 0.09803922, 0.10980393]]], dtype=float32)\n\nNote that floating point values are expected to have values in the range\n\\[0,1) and values outside this range are clipped. \n\n x = [[[1.0, 2.0, 3.0],\n [4.0, 5.0, 6.0]],\n [[7.0, 8.0, 9.0],\n [10.0, 11.0, 12.0]]]\n tf.image.adjust_jpeg_quality(x, 75)\n \u003ctf.Tensor: shape=(2, 2, 3), dtype=float32, numpy=\n array([[[1., 1., 1.],\n [1., 1., 1.]],\n [[1., 1., 1.],\n [1., 1., 1.]]], dtype=float32)\u003e\n\nNote that `jpeg_quality` 100 is still lossy compresson. \n\n x = tf.constant([[[1, 2, 3],\n [4, 5, 6]],\n [[7, 8, 9],\n [10, 11, 12]]], dtype=tf.uint8)\n tf.image.adjust_jpeg_quality(x, 100)\n \u003ctf.Tensor: shape(2, 2, 3), dtype=uint8, numpy=\n array([[[ 0, 1, 3],\n [ 3, 4, 6]],\n [[ 6, 7, 9],\n [ 9, 10, 12]]], dtype=uint8)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|----------------------------------------------------------------|\n| `image` | 3D image. The size of the last dimension must be None, 1 or 3. |\n| `jpeg_quality` | Python int or Tensor of type int32. jpeg encoding quality. |\n| `name` | A name for this operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Adjusted image, same shape and DType as `image`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|------------------------|---------------------------------|\n| `InvalidArgumentError` | quality must be in \\[0,100\\] |\n| `InvalidArgumentError` | image must have 1 or 3 channels |\n\n\u003cbr /\u003e"]]