Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython notebook read multiple images and display in CELL

How do I do the above ? This is my code but it doesn't work nothing is displayed

from PIL import Image
import glob
image_list = []
for filename in glob.glob('<my directory>.pgm'):
    im=Image.open(filename)
    image_list.append(im)

import matplotlib.pyplot as plt

for i in range(10):
    plt.figure()
    plt.imshow(image_list[i])

I would like it to be displayed in the cell

like image 993
Kong Avatar asked Jun 27 '16 13:06

Kong


People also ask

How do I import multiple pictures into a Jupyter notebook?

Use scipy. misc. imread(name='my_file. png') , this will return a Numpy array that you can then use to create a dataset.

What does %% capture do Python?

IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.


Video Answer


1 Answers

If you're interested in a much simpler and faster way of displaying images I recommend IPyPlot package:

import ipyplot

ipyplot.plot_images(images_list, max_images=20, img_width=150)

It's capable of displaying hundreds of images in a grid-like format within just 60-70ms

You would get a plot similar to this:
enter image description here

like image 181
Karol Żak Avatar answered Sep 22 '22 22:09

Karol Żak