Spaces:
Sleeping
Sleeping
Update utils_mask.py
Browse files- utils_mask.py +4 -14
utils_mask.py
CHANGED
|
@@ -83,30 +83,20 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
| 83 |
(parse_array == 12).astype(np.float32) + \
|
| 84 |
(parse_array == 13).astype(np.float32) + \
|
| 85 |
(parse_array == 5).astype(np.float32)
|
| 86 |
-
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
| 87 |
-
(parse_array == label_map["pants"]).astype(np.float32)
|
| 88 |
-
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
parse_mask_legs = np.logical_or.reduce((parse_array == label_map["left_leg"],
|
| 94 |
-
parse_array == label_map["right_leg"],
|
| 95 |
-
parse_array == label_map["skirt"],
|
| 96 |
-
parse_array == label_map["pants"])).astype(np.float32)
|
| 97 |
parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=6)
|
| 98 |
parse_mask_lower = np.maximum(parse_mask_lower, parse_mask_legs_dilated)
|
| 99 |
|
| 100 |
-
#
|
| 101 |
fill_gap_between_legs = cv2.morphologyEx(parse_mask_lower.astype(np.uint8), cv2.MORPH_CLOSE, np.ones((15, 15), np.uint8))
|
| 102 |
|
| 103 |
parse_mask = np.logical_or(parse_mask_upper, fill_gap_between_legs)
|
| 104 |
|
| 105 |
elif category == 'upper_body':
|
| 106 |
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
| 107 |
-
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
| 108 |
-
(parse_array == label_map["pants"]).astype(np.float32)
|
| 109 |
-
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
| 110 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
| 111 |
elif category == 'lower_body':
|
| 112 |
parse_mask = (parse_array == 6).astype(np.float32) + \
|
|
|
|
| 83 |
(parse_array == 12).astype(np.float32) + \
|
| 84 |
(parse_array == 13).astype(np.float32) + \
|
| 85 |
(parse_array == 5).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
+
# Fill only the gaps between the legs
|
| 88 |
+
parse_mask_legs = (parse_array == label_map["left_leg"]).astype(np.float32) + \
|
| 89 |
+
(parse_array == label_map["right_leg"]).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=6)
|
| 91 |
parse_mask_lower = np.maximum(parse_mask_lower, parse_mask_legs_dilated)
|
| 92 |
|
| 93 |
+
# Close the gap between the legs
|
| 94 |
fill_gap_between_legs = cv2.morphologyEx(parse_mask_lower.astype(np.uint8), cv2.MORPH_CLOSE, np.ones((15, 15), np.uint8))
|
| 95 |
|
| 96 |
parse_mask = np.logical_or(parse_mask_upper, fill_gap_between_legs)
|
| 97 |
|
| 98 |
elif category == 'upper_body':
|
| 99 |
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
| 100 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
| 101 |
elif category == 'lower_body':
|
| 102 |
parse_mask = (parse_array == 6).astype(np.float32) + \
|