[Python] Open / load image as numpy ndarray directly

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I used to use scipy which would load an image from file straight into an ndarray.

    from scipy import misc
    img = misc.imread('./myimage.jpg')
    type(img)
    >>> numpy.ndarray


    But now it gives me a DeprecationWarning and the docs say it will be removed in 1.2.0. and I should use imageio.imread instead. But:

    import imageio
    img = imageio.imread('./myimage.jpg')
    type(img)
    >>> imageio.core.util.Image


    I could convert it by doing

    img = numpy.array(img)


    But this seems hacky. Is there any way to load an image straight into a numpy array as I was doing before with scipy's misc.imread (other than using OpenCV)?

    Continue reading...

Compartilhe esta Página