python显示图片两种方法
1.利用Pillow包
未安装的可以通过pip install Pillow安装
from PIL import Image img = Image.open('notMNIST_large/A/aGFua28udHRm.png') img.show()
显示的图片如下:
2.利用matplotlib
同样可以通过pip进行安装
from PIL import Image import matplotlib.pyplot as plt img=Image.open('notMNIST_large/A/aGFua28udHRm.png') plt.figure("pic") plt.imshow(img) plt.show()
显示的图片如下:
感觉第二种跟matlab有点像,可以命名窗口,默认有坐标轴
fig = plt.figure()
ax = fig.add_subplot(121)
ax.imshow(img)
ax = fig.add_subplot(122)
ax.imshow(img, cmap = 'gray')
plt.show()
默认显示的图片格式是三通道的,设置显示灰度图片,显示效果如下: