Spaces:
Running
on
Zero
Running
on
Zero
Update utils_mask.py
Browse files- utils_mask.py +16 -13
utils_mask.py
CHANGED
@@ -78,25 +78,28 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
78 |
arms_right = (parse_array == 15).astype(np.float32)
|
79 |
|
80 |
if category == 'dresses':
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
|
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
leg_mask = (parse_array == 12).astype(np.float32) + \
|
90 |
-
(parse_array == 13).astype(np.float32)
|
91 |
|
92 |
# Fill gaps between legs
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
#
|
96 |
-
|
97 |
|
98 |
-
# Add the filled leg gaps to the parse_mask
|
99 |
-
parse_mask += leg_gap_filled
|
100 |
|
101 |
|
102 |
elif category == 'upper_body':
|
|
|
78 |
arms_right = (parse_array == 15).astype(np.float32)
|
79 |
|
80 |
if category == 'dresses':
|
81 |
+
# Initial dress mask without legs
|
82 |
+
parse_mask_upper = (parse_array == 7).astype(np.float32) + \
|
83 |
+
(parse_array == 4).astype(np.float32) + \
|
84 |
+
(parse_array == 5).astype(np.float32)
|
85 |
|
86 |
+
# Create a separate mask for the legs
|
87 |
+
parse_mask_legs = (parse_array == 12).astype(np.float32) + \
|
88 |
+
(parse_array == 13).astype(np.float32) + \
|
89 |
+
(parse_array == 6).astype(np.float32)
|
90 |
|
91 |
+
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
|
|
|
|
92 |
|
93 |
# Fill gaps between legs
|
94 |
+
leg_mask_filled = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
|
95 |
+
leg_mask_filled = cv2.erode(leg_mask_filled, np.ones((6, 6), np.uint8), iterations=6) # Optional: Erode back to original size
|
96 |
+
|
97 |
+
# Combine filled leg mask with upper body mask
|
98 |
+
parse_mask = np.maximum(parse_mask_upper, leg_mask_filled)
|
99 |
|
100 |
+
# Final dilation to ensure there are no small gaps
|
101 |
+
parse_mask = cv2.dilate(parse_mask.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=5)
|
102 |
|
|
|
|
|
103 |
|
104 |
|
105 |
elif category == 'upper_body':
|