python - ImageIO.imwrite "ValueError: 找不到以单图像模式写入指定文件的格式" for
问题描述
我正在尝试保存已处理的图像(从原始图像开始,想要将其保存回原始/dng/nef)这个给定的ndarray只是-1,0,1,其中某些像素超过了阈值
我无法理解这里的问题:
imageio.imsave('images/imagesTest', image.Red.ZthreshMap)
鉴于此,我得到了这个错误:
File "C:\Users\E\--\PycharmProjects\lib\site-packages\imageio\core\functions.py", line 303, in imwrite
writer = get_writer(uri, format, "i", **kwargs)
File "C:\Users\E\--\PycharmProjects\lib\site-packages\imageio\core\functions.py", line 227, in get_writer
"Could not find a format to write the specified file in %s mode" % modename
ValueError: Could not find a format to write the specified file in single-image mode
我确认以防万一我为函数提供了正确的数据类型:
<class 'numpy.ndarray'>
是什么类型所以应该可以正常工作。
所以我在指定文件类型的地方尝试了这个:
imageio.imsave('images/imagesTest.dng', image.Red.ZthreshMap, '.dng')
File "C:\Users\E\--\PycharmProjects\lib\site-packages\imageio\plugins\freeimage.py", line 127, in _append_data
self._bm.allocate(im)
File "C:\Users\E\--\PycharmProjects\lib\site-packages\imageio\plugins\_freeimage.py", line 825, in allocate
raise ValueError("Cannot write arrays of given type and shape.")
ValueError: Cannot write arrays of given type and shape.
这很奇怪,因为我仔细检查了形状并且:
print(image.Red.ZthreshMap.shape)
最终导致(1434, 2160)
有什么建议吗?
解决方案
如果您更好地阐明您正在尝试做什么,它会更容易帮助您。你为什么要“无压缩拍摄”?如果您的文件纯粹由 values 组成-1
,0
并且1
它应该很好地无损压缩,这肯定是有利的。
目前,可能有2个问题:
您尚未指定文件扩展名,因此
imageio
不知道您是否要保存 PNG、TIFF 或 JPEG您的一些值是
-1
,并且很少有图像格式可以保存负数,因为它们通常记录黑色以上的亮度,因此负数会比黑色更支持,因为这种情况不会发生,图像格式不会打扰为宝贵的空间负数。
推荐阅读
- r-markdown - 在 rmarkdown 中增加目录的宽度
- r - 写成`||`运算符的“条件或”(也称为“短路或”)如何在R中工作?
- ansible - Ansible,在剧本中使用可变内容时出现问题
- google-chrome - 当应用程序应该支持其他浏览器(如 chrome)时应该测试什么?
- r - 在 visIgraphnetwoork 中添加主标题
- jenkins - Jenkins 作业在循环中连续运行
- php - AD/LDAP:单击按钮登录后出现“无效的用户名/密码”
- typo3 - TYPO3 版本 10 多域
- sql - 查找具有特定日期格式的记录
- excel - VBA VLookup 方法不适用于数字和字符串