正确的导入语句应该是分开写的。请使用以下代码:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import colorsys

loopy = mpimg.imread(r'C:\Users\RKP\Desktop\Loopy.jpg') # 读取原图

# 将RGB图像转换为HSI图像
hsi = colorsys.rgb_to_hsv(loopy)

# 提取H、S、I三个通道的图像数据
h = hsi[:,:,0]
s = hsi[:,:,1]
i = hsi[:,:,2]

# 创建一个包含四个子图的图像
fig, axs = plt.subplots(2, 2, figsize=(10, 10))

# 在每个子图中显示图像和标题
axs[0, 0].imshow(loopy)
axs[0, 0].axis('off')
axs[0, 0].set_title('Loopy')

axs[0, 1].imshow(h, cmap='hsv')
axs[0, 1].axis('off')
axs[0, 1].set_title('Hue')

axs[1, 0].imshow(s, cmap='gray')
axs[1, 0].axis('off')
axs[1, 0].set_title('Saturation')

axs[1, 1].imshow(i, cmap='gray')
axs[1, 1].axis('off')
axs[1, 1].set_title('Intensity')

plt.tight_layout()  # 调整子图的布局,使标题不重叠
plt.show()

请确保你已经正确安装了matplotlib库。如果还有其他问题,请随时提问。

Matplotlib 导入错误: 'import matplotlib.image as mpimg import colorsys' 的正确写法

原文地址: https://www.cveoy.top/t/topic/pd8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录