pythonimage-processingscipyimage-formats

Scipy imsave and imread change format


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)

Solution

  • 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')