1

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?

E Wils
  • 21
  • 2
  • Normally only cameras and scanners create DNG files, relatively few libraries can write them, most can only be read. Try PNG or TIFF, maybe. – Mark Setchell Jul 21 '20 at 12:12
  • I'm shooting for next to no compression on the image... That's why I'm shooting for a raw sort of format – E Wils Jul 31 '20 at 13:28

1 Answers1

0

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.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I am working with Raw images and I want to maintain the integrity of all of the data I'm working with. The threshold for example is just telling me where there is an outlier after I calculate zscores across the whole image. Not all my files are like this (such as the preprocessed image) I specified the file extension as ".dng". I don't want to save them as PNG,TIFF, or JPEG. I suppose the threshold here though could perhaps not be of the DNG format but in general it hasn't been working – E Wils Aug 02 '20 at 18:45