How to show PIL Image in ipython notebook

前端 未结 12 686
悲&欢浪女
悲&欢浪女 2020-12-22 23:08

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-23 00:07

    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()
    

提交回复
热议问题