我注意到Tensorflow
Python
包提供了在读取文件后解码jpeg
,png
和gif
图像的标准过程。例如png
:
import tensorflow as tf
filename_queue = tf.train.string_input_producer(['/Image.png']) # list of files to read
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
decoded_image = tf.image.decode_png(value) # use png or jpg decoder based on your files.
然而,似乎缺少tiff
格式解码器。
那么tiff
文件有哪些解决方案?当然,我可以将输入图像转换为png
,但这似乎不是一个非常聪明的解决方案。
答案 0 :(得分:6)
正确,TIFF图像没有解码器。查看tensorflow/core/kernels,您会看到
decode_csv_op.cc
decode_gif_op.cc
decode_jpeg_op.cc
decode_png_op.cc
decode_raw_op.cc
否decode_tiff_op.cc
。这可能是社区贡献的良好目标。
答案 1 :(得分:0)
自 February 2019 起,一些(有限的和实验性的)TIFF 支持已添加为 Tensorflow I/O 库的一部分:
<块引用>添加了非常初步的 TIFF 支持。 TIFF 格式相当复杂,因此尚不支持 JPEG 等压缩格式,但可以根据需要添加。
目前可用的方法如下:
<块引用>tfio.experimental.image.decode_tiff
将 TIFF 编码的图像解码为 uint8 张量。
<块引用>tfio.experimental.image.decode_tiff_info
解码 TIFF 编码的图像元数据。
来自 Tensorflow tutorial 的示例用法:
import tensorflow as tf
import tensorflow.io as tfio
...
def parse_image(img_path: str) -> dict:
...
image = tf.io.read_file(img_path)
tfio.experimental.image.decode_tiff(image)
...