How to show PIL Image in ipython notebook

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

    If you are using the pylab extension, you could convert the image to a numpy array and use matplotlib's imshow.

    %pylab # only if not started with the --pylab option
    imshow(array(pil_im))
    

    EDIT: As mentioned in the comments, the pylab module is deprecated, so use the matplotlib magic instead and import the function explicitly:

    %matplotlib
    from matplotlib.pyplot import imshow 
    imshow(array(pil_im))
    

提交回复
热议问题