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()
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()
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()
Recommended Posts