简体   繁体   中英

ImageIO.imwrite “ValueError: Could not find a format to write the specified file in single-image mode” for

I'm trying to save images that were processed (started as Raw Image, want to save it back to Raw/dng/nef) This given ndarray is just -1,0,1 where certain pixels exceeded a threshold

I'm having trouble grasping what the issue is here:

imageio.imsave('images/imagesTest', image.Red.ZthreshMap)

Given this I get this error back:

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

I confirmed just in case that I'm supplying the function with the right data type:

<class 'numpy.ndarray'>

Is what the type is so that should work fine.

So I tried this where I specify the file type:

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.

Which is strange because I double checked the shape and:

print(image.Red.ZthreshMap.shape)

ends up resulting in (1434, 2160)

Any recommendations?

If you clarify better what you are trying to do, it'll be easier to help you. Why are you "shooting for no compression" ? If your file consists purely of values -1 , 0 and 1 it should compress very well - losslessly which is surely advantageous.

At the moment, there are likely 2 issues:

  • you haven't specified a file extension so imageio doesn't know if you want to save a PNG, TIFF or JPEG

  • some of your values are -1 , and few image formats can save negative numbers because they normally record the brightness above black, so a negative number would be backer than black and as that doesn't happen, image formats don't bother allowing valuable space for negative numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM