How to show image in Jupyter Notebook

See how you can show images in Jupyter Notebook using Python's built-in module display from IPython and the pillow (PIL) package's module Image that allows you to do image operations.

This notebook was created with MLJAR Studio

MLJAR Studio is Python code editior with interactive code recipes and local AI assistant.
You have code recipes UI displayed at the top of code cells.

Documentation

All required packages are automatically imported by MLJAR Studio for you so you don't have to worry about them.

# import packages
from IPython.display import display,HTML
from PIL import Image

You can display any image using these piece of code:

# variables:
path="/home/apjanusz/kon.png"

# code:
with Image.open(path) as i:
	display(i)

You can also modify size of image which you want to show:

# variables:
path="/home/apjanusz/kon.png"
size=200,200

# code:
with Image.open(path) as i:
	i.thumbnail(size)
	display(i)

Below there is a video, which shows how this notebook was created. Enjoy!

HTML("""<iframe width="560" height="315" src="https://www.youtube.com/embed/1R_VWxmSouQ?si=WM4rYbUrFooL2KgB" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>""")

Conclusion

Using IPython and PIL packages is one of the easiest and the most effective way to display image in the Jupyter Notebook but this is just the tip of the iceberg. You will see more in MLJAR Studio in the future.

Recipes used in the show-image-jupyter-notebook.ipynb

All code recipes used in this notebook are listed below. You can click them to check their documentation.

Packages used in the show-image-jupyter-notebook.ipynb

List of packages that need to be installed in your Python environment to run this notebook. Please note that MLJAR Studio automatically installs and imports required modules for you.

Similar notebooks

List of similar Python notebooks, so you can find more inspiration ๐Ÿ˜Š