python - 为什么调整图像大小最终也会改变通道?
问题描述
所以我在 python 中有这个代码,它使用 TensorFlow 打开一个图像并调整它的大小:
def parse_image(filename):
label = filename
image = tf.io.read_file(path+'/'+filename)
print(image.shape)
image = tf.image.decode_png(image)
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize(image, [340, 340])
print(image.shape)
return image, label
当我使用 OpenCV 打开测试灰度图像时:
img = cv2.imread(path+"/test.png")
print(img.shape) #returns (2133,3219,3)
但是当我在同一张图片上调用上述函数时:
image, label = parse_image('test.png')
print(image.shape) #returns (340,340,1)
我知道 340 x 340 是我刚刚设置的宽度和高度,但为什么频道会改变?我正在尝试计算结构相似性,但测试图像和我要比较的图像具有不同的通道,这会引发错误。最糟糕的是,它是这个特定的测试图像。其他灰度图像工作正常。
解决方案
推荐阅读
- javascript - 新成员加入 wix 时自动分配角色
- android - Firebase 云消息传递返回无效注册
- javascript - 从 React Hooks 中的购物项目中删除项目
- android - 使用音频速度 Ffmpeg 更改音频音高
- c++ - 我试图在 cpp 中使用向量来实现图形(检查路径是否......)。为什么“addNewEdge”函数不向邻接列表添加值?
- mongodb - 场
数据库表中不存在错误 - kubernetes - Kubernetes 临时存储限制和容器日志
- javascript - 下载弹出窗口中的内容
- scala - Scala:无法将数组传递给需要 Seq 或 Iterable 的函数
- google-apps-script - 使用对应的查询 ID 和查询名称保存数据