用jupyter导入一张彩色图像,按照R\G\B三个通道分别进行灰度图显示
时间: 2023-09-10 19:07:18 浏览: 116
```python
# 导入必要的库
import numpy as np
import matplotlib.pyplot as plt
from skimage import io, color
# 读取彩色图像
img = io.imread('example.jpg')
# 分离RGB通道
r = img[:, :, 0]
g = img[:, :, 1]
b = img[:, :, 2]
# 将每个通道转换为灰度图并进行显示
plt.figure(figsize=(10, 5))
plt.subplot(1, 4, 1)
plt.imshow(img)
plt.title('Original')
plt.subplot(1, 4, 2)
plt.imshow(r, cmap='gray')
plt.title('R Channel')
plt.subplot(1, 4, 3)
plt.imshow(g, cmap='gray')
plt.title('G Channel')
plt.subplot(1, 4, 4)
plt.imshow(b, cmap='gray')
plt.title('B Channel')
plt.show()
```
运行结果如下图所示:

阅读全文
相关推荐















