0

The function imwrite() on imageio (Python) seems to be rescaling image data prior to saving. My image data has values in the range [30, 255] but when I save it, it stretches the data so the final image spreads from [0, 255], hence creating "holes" in the histogram so as increasing overall contrast.

Is there any parameter to fix this and make imwrite() not to modify the data?

Thanks

So far I am setting a pixel to 0 to prevent this from happening:

prediction[0, 0, 0] = 0

(prediction is a [1024, 768, 3] array containing a colour photograph)

imageio.imwrite('prediction.png', prediction)
Guillermo Luijk
  • 199
  • 1
  • 7

1 Answers1

0

Fixed! I was using uint32 values instead of uint8, then imwrite() seems to perform some scaling corrections because it expects uint8 type. The problem is solved using:

prediction = np.round(prediction*255).astype('uint8')

Instead of converting to 32-bit integer, which I did at the beginning:

prediction = np.round(prediction*255).astype(int)
Guillermo Luijk
  • 199
  • 1
  • 7