学习笔记 python 图片读取与显示
模块
matplotlib.image
matplotlib.pyplot
import matplotlib.image as mping #用于读取图片
import matplotlib.pyplot as plt#用于显示图片
FOLD="plot"#我的图片放在同一目录的plot的文件夹中
plot1 = mping.imread(FOLD+"/Curve.PNG")
Plot2 = mping.imread(FOLD+"/Cat.PNG")
fig = plt.figure(figsize=(10,8),dpi=80)#dpi图片分辨率 figsize图片大小
plt.subplot(121)#两张图
plt.imshow(plot1)
plt.title('Curve')#标题
plt.subplot(121)
plt.imshow(plot2)
plt.axies('off')#不显示坐标轴
plt.show()
或者使用PIL 库的image.open()函数读取图像
from PIL import Image #在Python2中,PIL(Python Imaging Library)是一个非常常好用的图像处理库,但PIL不支持Python3,所以有人(Alex Clark和Contributors)提供了Pillow,可以在Python3中使用。
im = Image.open('lena.png')
im.show() #im.show 为 window10 自带的图像显示应用
#
print(im.mode)
print(im.size)