Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::DecodeImage
#include <image_ops.h>
Function for decode_bmp, decode_gif, decode_jpeg, and decode_png.
Summary
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.
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.
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.
Args:
- scope: A Scope object
- contents: 0-D. The encoded image bytes.
Optional attributes (see Attrs
):
- channels: Number of color channels for the decoded image.
- dtype: The desired DType of the returned Tensor.
- expand_animations: Controls the output shape of the returned op. 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:
Output
: 3-D with shape [height, width, channels]
or 4-D with shape [frame, height, width, channels]
..
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Public static functions
Channels
Attrs Channels(
int64 x
)
Dtype
Attrs Dtype(
DataType x
)
ExpandAnimations
Attrs ExpandAnimations(
bool x
)
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-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tensorflow::ops::DecodeImage Class Reference\n\ntensorflow::ops::DecodeImage\n============================\n\n`#include \u003cimage_ops.h\u003e`\n\nFunction for decode_bmp, decode_gif, decode_jpeg, and decode_png.\n\nSummary\n-------\n\nDetects whether an image is a BMP, GIF, JPEG, or PNG, and performs the appropriate operation to convert the input bytes string into a [Tensor](/versions/r2.14/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of type dtype.\n\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\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\nArgs:\n\n- scope: A [Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- contents: 0-D. The encoded image bytes.\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs#structtensorflow_1_1ops_1_1_decode_image_1_1_attrs)):\n\n- channels: Number of color channels for the decoded image.\n- dtype: The desired DType of the returned [Tensor](/versions/r2.14/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor).\n- expand_animations: Controls the output shape of the returned op. 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\nReturns:\n\n- [Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): 3-D with shape `[height, width, channels]` or 4-D with shape `[frame, height, width, channels]`..\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [DecodeImage](#classtensorflow_1_1ops_1_1_decode_image_1abfe660ccb54018226f2c9996ecbf3c18)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` contents)` ||\n| [DecodeImage](#classtensorflow_1_1ops_1_1_decode_image_1acc94a29044649186bbaeae5ea7f6873d)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` contents, const `[DecodeImage::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs#structtensorflow_1_1ops_1_1_decode_image_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|\n| [image](#classtensorflow_1_1ops_1_1_decode_image_1a62ff2512dc732de4d362ff6f3b8abb46) | `::`[tensorflow::Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n| [operation](#classtensorflow_1_1ops_1_1_decode_image_1a30fff2e0d4b15969c8b4ce06072682fc) | [Operation](/versions/r2.14/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n\n| ### Public functions ||\n|------------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_decode_image_1a6077da2c6006ea12234e0b88d5a469f5)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_decode_image_1aff2862dcabe12bf553b2fef38d64ea85)`() const ` | |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_decode_image_1a1ba8b5d74537595560c28dccb6ccdf38)`() const ` | |\n\n| ### Public static functions ||\n|-----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| [Channels](#classtensorflow_1_1ops_1_1_decode_image_1ac86e16998082169eda98bb162f933d33)`(int64 x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs#structtensorflow_1_1ops_1_1_decode_image_1_1_attrs) |\n| [Dtype](#classtensorflow_1_1ops_1_1_decode_image_1a503537bd342c512196908e619961f4dd)`(DataType x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs#structtensorflow_1_1ops_1_1_decode_image_1_1_attrs) |\n| [ExpandAnimations](#classtensorflow_1_1ops_1_1_decode_image_1a0e5f662b9728514d9dcc84f1b2483ab7)`(bool x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs#structtensorflow_1_1ops_1_1_decode_image_1_1_attrs) |\n\n| ### Structs ||\n|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::DecodeImage::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/decode-image/attrs) | Optional attribute setters for [DecodeImage](/versions/r2.14/api_docs/cc/class/tensorflow/ops/decode-image#classtensorflow_1_1ops_1_1_decode_image). |\n\nPublic attributes\n-----------------\n\n### image\n\n```text\n::tensorflow::Output image\n``` \n\n### operation\n\n```text\nOperation operation\n``` \n\nPublic functions\n----------------\n\n### DecodeImage\n\n```gdscript\n DecodeImage(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input contents\n)\n``` \n\n### DecodeImage\n\n```gdscript\n DecodeImage(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input contents,\n const DecodeImage::Attrs & attrs\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n``` \n\nPublic static functions\n-----------------------\n\n### Channels\n\n```text\nAttrs Channels(\n int64 x\n)\n``` \n\n### Dtype\n\n```carbon\nAttrs Dtype(\n DataType x\n)\n``` \n\n### ExpandAnimations\n\n```text\nAttrs ExpandAnimations(\n bool x\n)\n```"]]