Scipy imsave and imread change format

Baron Yugovich picture Baron Yugovich · Aug 13, 2018 · Viewed 10.5k times · Source

When I save the image, the format it has is numpy.uint16, when I load it, it is numpy.uint8, and it messes up the whole pipeline for me. How do I prevent this from happening?

I am calling

from scipy.misc import imread, imsave
image = imread(path)
imread(image_path)

Answer

Lakshay Sharma picture Lakshay Sharma · Aug 13, 2018

The imsave and imread methods are deprecated and will be removed in future versions of SciPy. Using imageio.imwrite and imageio.imread instead should solve this.

>>> import imageio
>>> img = imageio.imread('img.jpg')
>>> img.dtype
dtype('uint8')
>>> imageio.imwrite('img_saved.jpg', img)
>>> img_read = imageio.imread('img_saved.jpg')
>>> img_read.dtype
dtype('uint8')