如何在ipython笔记本中显示PIL图像 [英] How to show PIL Image in ipython notebook
本文介绍了如何在ipython笔记本中显示PIL图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
from PIL import Image
pil_im = Image.open('data/empire.jpg')
我想对它进行一些图像处理,然后在屏幕上显示.
我在python笔记本中显示PIL图像时遇到问题.
I would like to do some image manipulation on it, and then show it on screen.
I am having problem with showing PIL Image in python notebook.
我尝试过:
print pil_im
还有
pil_im
但是两个都给我:
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=569x800 at 0x10ECA0710>
推荐答案
您可以使用IPython的Module: display
加载图像.您可以从文档.
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)
已更新
由于OP的要求是使用PIL
,因此如果要显示嵌入式图像,也可以将matplotlib.pyplot.imshow
与numpy.asarray
一起使用,如下所示:
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))
如果您只需要预览而不是内联,则可以像这样使用show
:
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()
这篇关于如何在ipython笔记本中显示PIL图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文