Detects whether an image is a BMP, GIF, JPEG, or PNG, and performs the
appropriate operation to convert the input bytes string into a Tensor
of type dtype.
Args
contents
A Tensor of type string. 0-D. The encoded image bytes.
channels
An optional int. Defaults to 0. Number of color channels for
the decoded image.
dtype
The desired DType of the returned Tensor.
name
A name for the operation (optional)
expand_animations
An optional bool. Defaults to True. Controls the
shape of the returned op's output. If True, the returned op will produce
a 3-D tensor for PNG, JPEG, and BMP files; and a 4-D tensor for all GIFs,
whether animated or not. If, False, the returned op will produce a 3-D
tensor for all file types and will truncate animated GIFs to the first
frame.
Returns
Tensor with type dtype and a 3- or 4-dimensional shape, depending on
the file type and the value of the expand_animations parameter.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.io.decode_image\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/image_ops_impl.py#L3268-L3334) |\n\nFunction for `decode_bmp`, `decode_gif`, `decode_jpeg`, and `decode_png`.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.image.decode_image`](https://www.tensorflow.org/api_docs/python/tf/io/decode_image)\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.decode_image`](https://www.tensorflow.org/api_docs/python/tf/io/decode_image), [`tf.compat.v1.io.decode_image`](https://www.tensorflow.org/api_docs/python/tf/io/decode_image)\n\n\u003cbr /\u003e\n\n tf.io.decode_image(\n contents,\n channels=None,\n dtype=../../tf/dtypes#uint8,\n name=None,\n expand_animations=True\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Adversarial example using FGSM](https://www.tensorflow.org/tutorials/generative/adversarial_fgsm) - [Neural style transfer](https://www.tensorflow.org/tutorials/generative/style_transfer) - [Image Super Resolution using ESRGAN](https://www.tensorflow.org/hub/tutorials/image_enhancing) - [Fast Style Transfer for Arbitrary Styles](https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization) - [Frame interpolation using the FILM model](https://www.tensorflow.org/hub/tutorials/tf_hub_film_example) |\n\nDetects whether an image is a BMP, GIF, JPEG, or PNG, and performs the\nappropriate operation to convert the input bytes `string` into a `Tensor`\nof type `dtype`.\n| **Note:** `decode_gif` returns a 4-D array `[num_frames, height, width, 3]`, as opposed to `decode_bmp`, `decode_jpeg` and `decode_png`, which return 3-D arrays `[height, width, num_channels]`. Make sure to take this into account when constructing your graph if you are intermixing GIF files with BMP, JPEG, and/or PNG files. Alternately, set the `expand_animations` argument of this function to `False`, in which case the op will return 3-dimensional tensors and will truncate animated GIF files to the first frame.\n| **Note:** If the first frame of an animated GIF does not occupy the entire canvas (maximum frame width x maximum frame height), then it fills the unoccupied areas (in the first frame) with zeros (black). For frames after the first frame that does not occupy the entire canvas, it uses the previous frame to fill the unoccupied areas.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `contents` | A `Tensor` of type `string`. 0-D. The encoded image bytes. |\n| `channels` | An optional `int`. Defaults to `0`. Number of color channels for the decoded image. |\n| `dtype` | The desired DType of the returned `Tensor`. |\n| `name` | A name for the operation (optional) |\n| `expand_animations` | An optional `bool`. Defaults to `True`. Controls the shape of the returned op's output. If `True`, the returned op will produce a 3-D tensor for PNG, JPEG, and BMP files; and a 4-D tensor for all GIFs, whether animated or not. If, `False`, the returned op will produce a 3-D tensor for all file types and will truncate animated GIFs to the first frame. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| `Tensor` with type `dtype` and a 3- or 4-dimensional shape, depending on the file type and the value of the `expand_animations` parameter. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------|\n| `ValueError` | On incorrect number of channels. |\n\n\u003cbr /\u003e"]]