forked from rpautrat/SuperPoint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
29 lines (27 loc) · 992 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import matplotlib.pyplot as plt
def plot_imgs(imgs, titles=None, cmap='brg', ylabel='', normalize=False, ax=None, dpi=100):
n = len(imgs)
if not isinstance(cmap, list):
cmap = [cmap]*n
if ax is None:
_, ax = plt.subplots(1, n, figsize=(6*n, 6), dpi=dpi)
if n == 1:
ax = [ax]
else:
if not isinstance(ax, list):
ax = [ax]
assert len(ax) == len(imgs)
for i in range(n):
if imgs[i].shape[-1] == 3:
imgs[i] = imgs[i][..., ::-1] # BGR to RGB
ax[i].imshow(imgs[i], cmap=plt.get_cmap(cmap[i]),
vmin=None if normalize else 0,
vmax=None if normalize else 1)
if titles:
ax[i].set_title(titles[i])
ax[i].get_yaxis().set_ticks([])
ax[i].get_xaxis().set_ticks([])
for spine in ax[i].spines.values(): # remove frame
spine.set_visible(False)
ax[0].set_ylabel(ylabel)
plt.tight_layout()