python中利用matplotlib读取灰度图

代码为:

import matplotlib.pyplot as plt #用于显示图片
import matplotlib.image as mpimg # mpimg 用于读取图片

picdir = 'C:\\Users\\wyt\\Desktop\\test\\ship\\012400.jpg'
img = mpimg.imread(picdir)
plt.imshow(img)                                
plt.title('Original train image')   
plt.show()

显示结果如下,是以热量图的形式显示。

要想显示出灰度图,在使用代码

plt.imshow(img,cmap='Greys_r')  

 代替plt.imshow(img)即可

猜你喜欢

转载自blog.csdn.net/Mr_health/article/details/81264834