Spaces:
Runtime error
Runtime error
Plot only large objects
Browse files- label_prettify.py +9 -8
label_prettify.py
CHANGED
@@ -71,14 +71,15 @@ def seg_prettify(rgb_path, file_name):
|
|
71 |
|
72 |
for i in np.unique(seg_labels):
|
73 |
obj_idx_all = np.where(seg_labels == i)
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
|
83 |
plt.axis('off')
|
84 |
plt.savefig(file_name, bbox_inches='tight', transparent=True, pad_inches=0)
|
|
|
71 |
|
72 |
for i in np.unique(seg_labels):
|
73 |
obj_idx_all = np.where(seg_labels == i)
|
74 |
+
if len(obj_idx_all[0]) > 20: # only plot the label with its number of labelled pixel more than 20
|
75 |
+
obj_idx = random.randint(0, len(obj_idx_all[0]) - 1)
|
76 |
+
x, y = obj_idx_all[1][obj_idx], obj_idx_all[0][obj_idx]
|
77 |
+
obj_name = coco_label_map[int(i * 255)]
|
78 |
+
obj_name = obj_name.split(',')[0]
|
79 |
+
if islight(seg_map[int(y), int(x)]):
|
80 |
+
plt.text(x, y, obj_name, c='black', horizontalalignment='center', verticalalignment='center', clip_on=True)
|
81 |
+
else:
|
82 |
+
plt.text(x, y, obj_name, c='white', horizontalalignment='center', verticalalignment='center', clip_on=True)
|
83 |
|
84 |
plt.axis('off')
|
85 |
plt.savefig(file_name, bbox_inches='tight', transparent=True, pad_inches=0)
|