matplotlib实现显示伪彩色图像及色度条
更新时间:2019年12月07日 16:01:12 作者:sjtu_leexx
今天小编就为大家分享一篇matplotlib实现显示伪彩色图像及色度条,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
灰度图显示为伪彩色图
法一
import matplotlib.pyplot as plt img = plt.imread('C:/Users/leex/Desktop/lena.jpg') img_s = img[:,:,0]# 直接读入的img为3通道,这里用直接赋值的方法转为单通道 sc = plt.imshow(img_s) sc.set_cmap('hot')# 这里可以设置多种模式 plt.colorbar()# 显示色度条
效果
限制范围
import matplotlib.pyplot as plt img = plt.imread('C:/Users/leex/Desktop/lena.jpg') img_s = img[:,:,0] sc = plt.imshow(img_s) sc.set_cmap('hot') sc.set_clim(0,100) plt.colorbar()
效果
法二
import matplotlib.pyplot as plt img = plt.imread('C:/Users/leex/Desktop/lena.jpg') img_s = img[:,:,0] sc = plt.imshow(img_s, cmap = plt.cm.jet)# 设置cmap为RGB图 plt.colorbar()# 显示色度条
效果
限制范围
import matplotlib.pyplot as plt img = plt.imread('C:/Users/leex/Desktop/lena.jpg') img_s = img[:,:,0] sc = plt.imshow(img_s, vmin=0, vmax = 100, cmap = plt.cm.jet)# 限制范围为0-100 plt.colorbar()
效果
以上这篇matplotlib实现显示伪彩色图像及色度条就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
一文让你彻底搞懂Python中__str__和__repr__
这篇文章主要介绍了Python中的__str__和__repr__的异同,__str__和__repr__是基本的内置方法,文中有详细的代码示例,感兴趣的同学可以参考阅读下2023-05-05
最新评论