How to show PIL Image in ipython notebook

前端 未结 12 1427
抹茶落季
抹茶落季 2020-12-22 23:18

This is my code

from PIL import Image
pil_im = Image.open(\'data/empire.jpg\')

I would like to do some image manipulation on it, and then s

12条回答
  •  难免孤独
    2020-12-22 23:56

    A cleaner Python3 version that use standard numpy, matplotlib and PIL. Merging the answer for opening from URL.

    import matplotlib.pyplot as plt
    from PIL import Image
    import numpy as np
    
    pil_im = Image.open('image.jpg')
    ## Uncomment to open from URL
    #import requests
    #r = requests.get('https://www.vegvesen.no/public/webkamera/kamera?id=131206')
    #pil_im = Image.open(BytesIO(r.content))
    im_array = np.asarray(pil_im)
    plt.imshow(im_array)
    plt.show()
    

提交回复
热议问题