View images in Matplotlib

Display anyway

If you just want to display it, you can use the Image.show () method. The standard viewer for each OS opens.

#coding:utf-8
from PIL import Image

#Loading images
im = Image.open("./achan.jpg ")

#display
im.show()

py2

Ordinary python program

usually? If you want to display it in your Python program, you can use Matplotlib as well as the graph. It's convenient because you can put captions in it.

#coding:utf-8
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

#Loading images
im = Image.open("./achan.jpg ")

#Convert image to array
im_list = np.asarray(im)
#pasting
plt.imshow(im_list)
#display
plt.show()

py2

Apparently the number of pixels is mapped to the coordinates.

Jupyter

If you want to display it in Jupyter (IPython) notebook, use% matplotlib inline at the beginning of the program. Then, it will be displayed inline (otherwise, another window will open).

There is also a way to add the inline option when starting the notebook. If you don't want to change the code, that might be better.

#coding:utf-8
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

#Declaration for inline display in Jupyter
%matplotlib inline #add to

#Loading images
im = Image.open("./achan.jpg ")

#Convert image to array
im_list = np.asarray(im)
#pasting
plt.imshow(im_list)
#display
plt.show()

py2

Recommended Posts

View images in Matplotlib
How to view images in Django's Admin
Put matplotlib in Centos7.
2D plot in matplotlib
Base64 encoding images in Python 3
Embed matplotlib graphs in Tkinter
View matplotlib plots on Tensorboard
Number recognition in images with Python
View photos in Python and html
[Image connection] Arrange images in tiles
Show axes as percentages in Matplotlib
How to collect images in Python
Extract text from images in Python
Draw retention rate graph in Matplotlib
View graphs inline in Jupyter Notebook
Heatmap with Dendrogram in Python + matplotlib
Make matplotlib Japanese compatible in 3 minutes
Show dividing lines in matplotlib histogram
The first step in Python Matplotlib
Working with DICOM images in Python
Watershed method in 3D images using ImageJ
Display LaTeX notation formulas in Python, matplotlib
View the implementation source code in iPython
How to suppress display error in matplotlib
View image after Data Augmentation in PyTorch
[Python] View dataframe in VScode debug console
Displaying candlestick charts in Python (matplotlib edition)
Specify the color in the matplotlib 2D map
Summary of frequently used commands in matplotlib
Display matplotlib diagrams in a web application
Put Japanese fonts in images with Colaboratory
Jupyter, numpy, matplotlib notes used in reports
Implement a custom View Decorator in Pyramid
Display Matplotlib xy graph in PySimple GUI.
Download images from URL list in Python
Ajax in Django (using generic class view)
Separation of design and data in matplotlib
I want to embed Matplotlib in PySimpleGUI
How to implement Scroll View in pythonista 1
Get rid of DICOM images in Python
Read text in images with python OCR
How to draw OpenCV images in Pygame
Why can't I install matplotlib in python! !!
The date is displayed incorrectly in matplotlib.