文章目录
最近看到的关于 tf.image.resize 函数吐槽有点多,我也来参与一下好了。
在习惯使用 cv 及 numpy 搭配对图像实现一些变换的背景下,使用 tf 的图像处理函数可能会带来很多数据层面的麻烦。
使用 image = cv2.imread(path)
得到的结果是 uint8 类型的图像,继续对 image 进行resize 等操作得到的返回结果仍然是 uint8,像素值的 range 仍然维持 0~255。然而这些整齐划一的操作在 tf.image.resize
中无法保证。
在 tf 中读取 jpg 格式图片信息得到的 image 是 uint8 类型。
image_raw_data = gfile.FastGFile(file_name, 'rb').read()
image = tf.image.decode_jpeg(image_raw_data)