如何在Matplotlib中显示不同通道的彩色图像? 使用misc.imread来将图像分割成红色、绿色和蓝色通道,可以按以下步骤进行− 设置图形大小并调整子图之间和周围的填充。 从文件中读取图像并转换成数组。 创建一个带有子图的图形。 创建颜色映射和标题的列表。 将轴、图像、标题和颜色映射压缩在一起。 迭代压缩的对象并设置每个通道图像的标题。 使用 show() 方法显示图形。 例子 import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True image = plt.imread('bird.png') titles = ['带红色通道', '带绿色通道', '带蓝色通道'] cmaps = [plt.cm.Reds_r, plt.cm.Greens_r, plt.cm.Blues_r] fig, axes = plt.subplots(1, 3) objs = zip(axes, (image, *image.transpose(2, 0, 1)), titles, cmaps) for ax, channel, title, cmap in objs: ax.imshow(channel, cmap=cmap) ax.set_title(title) ax.set_xticks(()) ax.set_yticks(()) plt.show() PythonCopy 输入图像 输出图像