[Python] opening a JPG file in Google Colab

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I have this code in to open a PNG file on google colab.

    import numpy as np
    import matplotlib
    from PIL import Image
    %matplotlib inline
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg

    img = mpimg.imread('https://www.seekpng.com/png/full/161-1615982_doc-back-to-the-
    future-png-doc-back.png')

    imgplot = plt.imshow(img)


    The problem is that this code only works for PNG files. I have trouble opening a JPG file, and a GIF file in Google Colab. I would like to open a picture with its image address from the web, just like the one from the previous code. I know you can open JPG files with this code.

    from PIL import Image
    img = Image.open("https://upload.wikimedia.org/wikipedia/commons/c/c2/Girl_in_front_of_a_green_background.jpg")
    img.show()


    but it gives me the following error when compiling. FileNotFoundError: [Errno 2] No such file or directory:

    Continue reading...

Compartilhe esta Página