123456789101112131415161718192021222324 |
- import numpy as np
- import matplotlib.pyplot as plt
- def plot_crops(crops, title, scatter_mid=False, names=None):
- n_crops = crops.shape[0]
- if n_crops == 0: return
- rows = int(np.ceil(np.sqrt(n_crops)))
- cols = int(np.ceil(n_crops / rows))
- fig, axs = plt.subplots(rows, cols, figsize=(16,9))
- fig.suptitle(title, fontsize=16)
- for i, crop in enumerate(crops):
- ax = axs[np.unravel_index(i, axs.shape)]
- if names is not None:
- ax.set_title(names[i])
- ax.imshow(crop)
- ax.axis("off")
- if scatter_mid:
- middle_h, middle_w = crop.shape[0] / 2, crop.shape[1] / 2
- ax.scatter(middle_w, middle_h, marker="x")
|