python - 使用 cv2 和 Matplotlib 从 8 个子文件夹中打印 5 张图像
问题描述
我正在尝试显示每个子文件夹中的 5 张图像,这是图像类。我的代码仅显示 5 个头等舱 (AK) 的图像。我还将图像的标题显示到其对应的类。请参考下面的代码。
label = ['AK', 'BCC','BKL','DF','MEL','NV','SCC','VASC']
label_images = []
classes = [ 'Actinic Keratoses', 'Basal cell carcinoma', 'Benign Keratosis-like lesions',
'Dermatofibroma','Melanoma', 'Melanocytic nevi', 'Squamous cell carcinoma' , 'Vascular lesions']
fig = plt.figure(figsize=(20, 20))
for l in label:
dir_path = os.path.join(path,l)
for i,file in enumerate(os.listdir(dir_path)[0:5]):
fullpath = dir_path+ "/" + file
img=cv2.imread(fullpath)
plt.subplot(8, 5, i+1)
plt.imshow(img)
plt.axis('off')
if i%5 == 0:
title = int(i/5)
plt.title(classes[title], loc='left', size=20)
plt.tight_layout()
plt.show()
解决方案
推荐阅读
- android - Flutter Dart 在构建期间使用过多内存
- cas - Apereo CAS 协议:是否允许 CAS 服务器更改 URL?
- python - Pycharm:安装 Pycurl 包但未找到 (ModuleNotFoundError)
- ios - 数组映射,斯威夫特
- sql - 在不使用临时表/外部表概念的情况下从文本/xls 文件获取更新/删除 SQL 语句的输入的最简单方法
- mongodb - 我想将 bcrypt.compare 与 mongoose/mongo enginee 搜索一起使用
- jquery - 模态弹出窗口,并在新选项卡中打开一个链接
- android - 为 Unity 上的 3D 角色添加适用于 Android 的操纵杆和触摸控件
- c - CS50 C 发出错误:数组初始值设定项必须是初始值设定项列表或字符串文字
- reactjs - 使用过滤器和挂钩的搜索功能