首页 > 解决方案 > 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)

有什么建议吗?

标签: pythonimagepython-imageio

解决方案


如果您更好地阐明您正在尝试做什么,它会更容易帮助您。你为什么要“无压缩拍摄”?如果您的文件纯粹由 values 组成-10并且1它应该很好地无损压缩,这肯定是有利的。

目前,可能有2个问题:

  • 您尚未指定文件扩展名,因此imageio不知道您是否要保存 PNG、TIFF 或 JPEG

  • 您的一些值是-1,并且很少有图像格式可以保存负数,因为它们通常记录黑色以上的亮度,因此负数会比黑色更支持,因为这种情况不会发生,图像格式不会打扰为宝贵的空间负数。


推荐阅读