网络编程
位置:首页>> 网络编程>> Python编程>> python中利用matplotlib读取灰度图的例子

python中利用matplotlib读取灰度图的例子

作者:Mr_health  发布时间:2022-08-08 08:25:36 

标签: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()

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

python中利用matplotlib读取灰度图的例子

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


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

代替plt.imshow(img)即可

来源:https://blog.csdn.net/Mr_health/article/details/81264834

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com