1

I recently asked a question about saving images with negative values using PIL. Now I want to try this with OpenCV (in python). I would like the images to be saved in an image format (not 'mat' format). My understanding is tiff is the only format capable of saving negative values.

Is it possible to save/load images with negative values using opencv? If so, how can this be done?

Community
  • 1
  • 1
Greg Samson
  • 1,267
  • 2
  • 11
  • 21
  • I think that's dumb / the wrong approach but well... if you got your PIL-approach working, just use the PIL-based function to save the opencv array [after preparing](http://stackoverflow.com/questions/13576161/convert-opencv-image-into-pil-image-in-python-for-use-with-zbar-library). – sascha Nov 22 '16 at 20:53
  • Why do you think this is dumb? I do not want to mean shift the data because the min/max can be unknown, which also means that dividing by the highest possible max (for an int16= 32767) could result in issues. – Greg Samson Nov 22 '16 at 21:35
  • Well. There is no perfect answer without assumptions. Every image format itself is based on assumptions. With the correct assumptions for your task, there is a much better approach possible. I would be scared of your approach,m even more after you said, that min/max is unknown. Even tiff has it's limits regarding negative values. Maybe even starting at the bounds of -32k.(A safe approach without much implementation-work would be to stick to general matrices which can then be combined with compressed serialization; maybe you want to stick to img-formats because of compr; but it won't gain much) – sascha Nov 22 '16 at 21:40
  • 1
    I don't keep them as image formats, the goal is to make them readable in other packages that support reading images. I have also used HDF format for these, but there are many more image operations that are supported when they are loaded from image files. The values are known to be greater than -32k, as the original containers are int16 even if there was a known minimum there are issues. The bias itself is important information that I want to preserve. Sure there are other approaches, but you are assuming that I have not looked at those, I have, and I am, I am also considering this approach. – Greg Samson Nov 23 '16 at 01:44
  • Any luck? I need 32bit signed Ints and I'm finding that they're just not well supported. – J.Hirsch Dec 20 '19 at 02:30

0 Answers0