|
4 | 4 | import numpy as np |
5 | 5 | import matplotlib.pyplot as plt |
6 | 6 | from tinysam import sam_model_registry, SamPredictor |
7 | | -from demo import show_mask, show_points, show_box |
| 7 | + |
| 8 | +def show_mask(mask, ax, random_color=False): |
| 9 | + if random_color: |
| 10 | + color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0) |
| 11 | + else: |
| 12 | + color = np.array([30/255, 144/255, 255/255, 0.6]) |
| 13 | + h, w = mask.shape[-2:] |
| 14 | + mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1) |
| 15 | + ax.imshow(mask_image) |
| 16 | + |
| 17 | +def show_points(coords, labels, ax, marker_size=375): |
| 18 | + pos_points = coords[labels==1] |
| 19 | + neg_points = coords[labels==0] |
| 20 | + ax.scatter(pos_points[:, 0], pos_points[:, 1], color='green', marker='*', s=marker_size, edgecolor='white', linewidth=1.25) |
| 21 | + ax.scatter(neg_points[:, 0], neg_points[:, 1], color='red', marker='*', s=marker_size, edgecolor='white', linewidth=1.25) |
| 22 | + |
| 23 | +def show_box(box, ax): |
| 24 | + x0, y0 = box[0], box[1] |
| 25 | + w, h = box[2] - box[0], box[3] - box[1] |
| 26 | + ax.add_patch(plt.Rectangle((x0, y0), w, h, edgecolor='green', facecolor=(0,0,0,0), lw=2)) |
8 | 27 |
|
9 | 28 | sys.path.append("./tinysam") |
10 | 29 |
|
|
0 commit comments