1
2
3
4
5
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
%matplotlib inline #jupyter中使用,需要这一行
import os
import cv2
1
2
3
4
5
#调整
path = '/data/lwb/data/HPA/train/mix/pos/'
N = 49
row = 7
col = 7
1
2
3
4
5
6
7
img = []
for i in os.listdir(path)[:N]:
img_path = os.path.join(path,i)
img_bgr = cv2.imread(img_path)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img.append(img_rgb)
len(img)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fig = plt.figure(figsize=(10, 10))
grid = ImageGrid(fig, 111, # 类似绘制子图 subplot(111)
nrows_ncols=(row, col), # 创建 row 行 col 列的 axes 网格
axes_pad=0.05, # 网格间距
share_all=True
)

# 遍历每张图像
for ax, im in zip(grid, img):
ax.imshow(im)
ax.axis('off')

plt.tight_layout()
plt.show()