您的位置:首页 > 编程语言 > PHP开发

matplotlib实现显示伪彩色图像及色度条

2019-12-08 07:09 2486 查看

灰度图显示为伪彩色图

法一

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实现显示伪彩色图像及色度条就是小编分享给大家的全部内容了,希望能给大家一个参考

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息