利用RGB格式显示图像,只保留R通道图像数据,G、B通道数据置零,观察显示效果。
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
#读入图片
im = plt.imread('dog.jpg')
print('the data demension of input image is:')
print(im.shape)
plt.subplot(221)
plt.title('org image')
plt.imshow(im)
运行结果:
只保留R通道图像数据,G、B通道数据置零。即将img数组中的后两列置零。
# 利用RGB格式显示图像,只保留R通道图像数据,G、B通道数据置零,观察显示效果。
R_img = im.copy()
R_img[:, :, 1] = 0
R_img[:, :, 2] = 0
plt.subplot(222)
plt.title('R_img')
plt.imshow(R_img)
运行结果: