How to show PIL Image in ipython notebook

前端 未结 12 672
悲&欢浪女
悲&欢浪女 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-22 23:58

    You can open an image using the Image class from the package PIL and display it with plt.imshow directly.

    # First import libraries.
    from PIL import Image
    import matplotlib.pyplot as plt
    
    # The folliwing line is useful in Jupyter notebook
    %matplotlib inline
    
    # Open your file image using the path
    img = Image.open()
    
    # Since plt knows how to handle instance of the Image class, just input your loaded image to imshow method
    plt.imshow(img)
    

提交回复
热议问题