Getting closer to understanding what I need from the system
Browse files- understand.py +17 -0
understand.py
CHANGED
@@ -78,6 +78,21 @@ def show_mask_for_number(map_to_use, label_id):
|
|
78 |
plt.imshow(visual_mask)
|
79 |
plt.show()
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
def get_coordinates_for_bb_simple(map_to_use, label_id):
|
83 |
"""
|
@@ -225,6 +240,8 @@ def contour_map(map_to_use, label_id):
|
|
225 |
mask = (map_to_use.numpy() == label_id)
|
226 |
|
227 |
visual_mask = (mask* 255).astype(np.uint8)
|
|
|
|
|
228 |
|
229 |
"""
|
230 |
>>> mask = (results["segmentation"].cpu().numpy() == 1)
|
|
|
78 |
plt.imshow(visual_mask)
|
79 |
plt.show()
|
80 |
|
81 |
+
def show_mask_for_number_over_image(map_to_use, label_id, image_object):
|
82 |
+
"""
|
83 |
+
map_to_use: You have to pass in `results["segmentation"]`
|
84 |
+
"""
|
85 |
+
if torch.cuda.is_available():
|
86 |
+
mask = (map_to_use.cpu().numpy() == label_id)
|
87 |
+
else:
|
88 |
+
mask = (map_to_use.numpy() == label_id)
|
89 |
+
|
90 |
+
visual_mask = (mask* 255).astype(np.uint8)
|
91 |
+
visual_mask = Image.fromarray(visual_mask)
|
92 |
+
plt.imshow(image_object)
|
93 |
+
plt.imshow(visual_mask, alpha=0.25)
|
94 |
+
plt.show()
|
95 |
+
|
96 |
|
97 |
def get_coordinates_for_bb_simple(map_to_use, label_id):
|
98 |
"""
|
|
|
240 |
mask = (map_to_use.numpy() == label_id)
|
241 |
|
242 |
visual_mask = (mask* 255).astype(np.uint8)
|
243 |
+
contours, hierarchy = cv.findContours(visual_mask, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
|
244 |
+
return contours, hierarchy
|
245 |
|
246 |
"""
|
247 |
>>> mask = (results["segmentation"].cpu().numpy() == 1)
|