试读部分
图像基础 导入相应的包: import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
%matplotlib inline
导入图像 我们首先导入上面的图像,注意 matplotlib 默认只支持 PNG 格式的图像,我们可以使用 mpimg.imread 方法读入这幅图像: img = mpimg.imread('stinkbug.png')
img.shape
(375L, 500L, 3L)
这是一个 375 x 500 x 3 的 RGB 图像,并且每个像素使用 uint8 分别表示 RGB 三个通道的值。不过在处理的时候,matplotlib 将它们的值归一化到 0.0~1.0 之间: img.dtype
dtype('float32')
显示图像 使用 plt.imshow() 可以显示图像: imgplot = plt.imshow(img)
伪彩色图像 从单通道模拟彩色图像: lum_img = img[:,:,0]
imgplot = plt.imshow(lum_img)
改变 colormap imgplot = plt.imshow(lum_img)
imgplot.set_cmap('hot')
imgplot = plt.imshow(lum_img)
imgplot.set_cmap('spectral')
显示色度条: imgplot = plt.imshow(lum_img)
imgplot.set_cmap('spectral')
plt.colorbar()
plt.show()
限制显示范围 先查看直方图: plt.hist(lum_img.flatten(), 256, range=(0.0,1.0), ……
本文为 VIP 文章,已展示部分内容,
开通 VIP 后查看全文
觉得这篇文章有帮助?
点个赞,或赞赏支持作者持续创作