How to show PIL Image in ipython notebook

前端 未结 12 673
悲&欢浪女
悲&欢浪女 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:41

    You can use IPython's Module: display to load the image. You can read more from the Doc.

    from IPython.display import Image 
    pil_img = Image(filename='data/empire.jpg')
    display(pil_img)
    

    updated

    As OP's requirement is to use PIL, if you want to show inline image, you can use matplotlib.pyplot.imshow with numpy.asarray like this too:

    from matplotlib.pyplot import imshow
    import numpy as np
    from PIL import Image
    
    %matplotlib inline
    pil_im = Image.open('data/empire.jpg', 'r')
    imshow(np.asarray(pil_im))
    

    If you only require a preview rather than an inline, you may just use show like this:

    pil_im = Image.open('data/empire.jpg', 'r')
    pil_im.show()
    

提交回复
热议问题