Skip to content
Advertisement

How to show PIL Image in ipython notebook

This is my code

JavaScript

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:

JavaScript

And just

JavaScript

But both just give me:

JavaScript

Advertisement

Answer

Updated 2021/11/17

When using PIL/Pillow, Jupyter Notebooks now have a display built-in that will show the image directly, with no extra fuss.

JavaScript

Jupyter will also show the image if it is simply the last line in a cell (this has changed since the original post). Thanks to answers from @Dean and @Prabhat for pointing this out.

Other Methods

From File

You can also use IPython’s display module to load the image. You can read more from the doc.

JavaScript

From PIL.Image Object

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:

JavaScript

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

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement