Asked By – WebOrCode
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 show it on screen.
I am having problem with showing PIL Image in python notebook.
I have tried:
But both just give me:
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=569x800 at 0x10ECA0710>
Now we will see solution for issue: How to show PIL Image in ipython notebook
When using PIL/Pillow, Jupyter Notebooks now have a
display built-in that will show the image directly, with no extra fuss.
You can also use IPython’s
display module 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)
From PIL.Image Object
As OP’s requirement is to use
PIL, if you want to show inline image, you can use
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()