参考自tf2.1
官方文档:
https://www.tensorflow.org/api_docs/python/tf/io/decode_jpeg
Decode a JPEG-encoded image to a uint8 tensor.
将JPEG编码的图像解码为uint8张量。
tf.io.decode_jpeg(
contents, channels=0, ratio=1, fancy_upscaling=True,
try_recover_truncated=False, acceptable_fraction=1, dct_method='', name=None
)
The attr channels
indicates the desired number of color channels for the decoded image.
参数channels
表示解码图像所需的颜色通道数
Accepted values are:
channels
可接受的值有:
- 0: Use the number of channels in the JPEG-encoded image.
- 0: 默认使用当前JPEG编码图像中的通道数
- 1: output a grayscale image.
- 1: 输出一张灰度图
- 3: output an RGB image.
- 3: 输出一张RGB三通道的图片
If needed, the JPEG-encoded image is transformed to match the requested number of color channels.
如果需要,可以对JPEG编码的图像进行转换以匹配所需数量的颜色通道。
The attr ratio
allows downscaling the image by an integer factor during decoding. Allowed values are: 1, 2, 4, and 8. This is much faster than downscaling the image later.
参数ratio
允许在解码期间将图像按比例缩小整数倍。
允许的值有:1,2,4和8。这比之后再缩小图像要快得多
This op also supports decoding PNGs and non-animated GIFs since the interface is the same, though it is cleaner to use tf.image.decode_image
.
该函数还支持解码PNG和非动画GIF,因为接口相同,不过不如使用tf.image.decode_image
,这样代码可读性更高。
Args:
-
contents: A Tensor of type string. 0-D. The JPEG-encoded image.
-
contents: 一个0维的string类型的张量。即JPEG编码的图像内容。
-
channels: An optional int. Defaults to 0. Number of color channels for the decoded image.
-
channels: 一个可选的整数。默认为0。指定解码图像的颜色通道数。
-
ratio: An optional int. Defaults to 1. Downscaling ratio.
-
ratio: 指定缩图比例,可选参数,默认为1。
-
fancy_upscaling: An optional bool. Defaults to True. If true use a slower but nicer upscaling of the chroma planes (yuv420/422 only).
-
fancy_upscaling:布尔值,默认为True,如果为True,则使用较慢但更好的色度平面升频(仅适用于yuv420 / 422)。
-
try_recover_truncated: An optional bool. Defaults to False. If true try to recover an image from truncated input.
-
try_recover_truncated:一个可选的布尔值,默认为False,如果为True,则尝试从截断的输入中恢复图像。
-
acceptable_fraction: An optional float. Defaults to 1. The minimum required fraction of lines before a truncated input is accepted.
-
acceptable_fraction:一个可选的float值,默认为1。接受截断的输入之前需要的最小行分数。
-
dct_method: An optional string. Defaults to
""
string specifying a hint about the algorithm used for decompression.
Defaults to""
which maps to a system-specific default.
Currently valid values are [“INTEGER_FAST”, “INTEGER_ACCURATE”].
The hint may be ignored (e.g., the internal jpeg library changes to a version that does not have that specific option.) -
dct_method:可选字符串参数,默认为
""
字符串,用于指定解压缩算法。
默认为""
,将映射到系统指定的默认算法。
一般的有效值是["INTEGER_FAST", "INTEGER_ACCURATE"]
.
但是该参数也有可能被忽略(例如:若计算机内部的jpeg库变更了版本,而该版本没有指定的选项) -
name: A name for the operation (optional).
-
name:(可选)为操作指定一个名字。
Returns:
- A Tensor of type uint8.
- 类型为uint8的张量