Spaces:
Running
on
Zero
Running
on
Zero
Update utils_mask.py
Browse files- utils_mask.py +7 -9
utils_mask.py
CHANGED
@@ -85,10 +85,10 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
85 |
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
86 |
|
87 |
# Create a mask for the legs (including skirts and pants)
|
88 |
-
parse_mask_legs = (parse_array == label_map["skirt"]
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
# Dilate the leg mask to ensure coverage and fill gaps
|
94 |
parse_mask_legs = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
|
@@ -101,7 +101,6 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
101 |
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
102 |
(parse_array == label_map["pants"]).astype(np.float32)
|
103 |
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
104 |
-
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
105 |
elif category == 'lower_body':
|
106 |
parse_mask = (parse_array == 6).astype(np.float32) + \
|
107 |
(parse_array == 12).astype(np.float32) + \
|
@@ -110,7 +109,6 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
110 |
parser_mask_fixed += (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
|
111 |
(parse_array == 14).astype(np.float32) + \
|
112 |
(parse_array == 15).astype(np.float32)
|
113 |
-
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
114 |
else:
|
115 |
raise NotImplementedError
|
116 |
|
@@ -154,13 +152,13 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
154 |
parser_mask_fixed += hands_left + hands_right
|
155 |
|
156 |
parser_mask_fixed = np.logical_or(parser_mask_fixed, parse_head)
|
157 |
-
parse_mask = cv2.dilate(parse_mask, np.ones((5, 5), np.
|
158 |
if category == 'dresses' or category == 'upper_body':
|
159 |
neck_mask = (parse_array == 18).astype(np.float32)
|
160 |
-
neck_mask = cv2.dilate(neck_mask, np.ones((5, 5), np.
|
161 |
neck_mask = np.logical_and(neck_mask, np.logical_not(parse_head))
|
162 |
parse_mask = np.logical_or(parse_mask, neck_mask)
|
163 |
-
arm_mask = cv2.dilate(np.logical_or(im_arms_left, im_arms_right).astype('float32'), np.ones((5, 5), np.
|
164 |
parse_mask += np.logical_or(parse_mask, arm_mask)
|
165 |
|
166 |
parse_mask = np.logical_and(parser_mask_changeable, np.logical_not(parse_mask))
|
|
|
85 |
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
86 |
|
87 |
# Create a mask for the legs (including skirts and pants)
|
88 |
+
parse_mask_legs = np.logical_or.reduce((parse_array == label_map["skirt"],
|
89 |
+
parse_array == label_map["pants"],
|
90 |
+
parse_array == label_map["left_leg"],
|
91 |
+
parse_array == label_map["right_leg"])).astype(np.float32)
|
92 |
|
93 |
# Dilate the leg mask to ensure coverage and fill gaps
|
94 |
parse_mask_legs = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
|
|
|
101 |
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
102 |
(parse_array == label_map["pants"]).astype(np.float32)
|
103 |
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
|
|
104 |
elif category == 'lower_body':
|
105 |
parse_mask = (parse_array == 6).astype(np.float32) + \
|
106 |
(parse_array == 12).astype(np.float32) + \
|
|
|
109 |
parser_mask_fixed += (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
|
110 |
(parse_array == 14).astype(np.float32) + \
|
111 |
(parse_array == 15).astype(np.float32)
|
|
|
112 |
else:
|
113 |
raise NotImplementedError
|
114 |
|
|
|
152 |
parser_mask_fixed += hands_left + hands_right
|
153 |
|
154 |
parser_mask_fixed = np.logical_or(parser_mask_fixed, parse_head)
|
155 |
+
parse_mask = cv2.dilate(parse_mask.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=5)
|
156 |
if category == 'dresses' or category == 'upper_body':
|
157 |
neck_mask = (parse_array == 18).astype(np.float32)
|
158 |
+
neck_mask = cv2.dilate(neck_mask.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=1)
|
159 |
neck_mask = np.logical_and(neck_mask, np.logical_not(parse_head))
|
160 |
parse_mask = np.logical_or(parse_mask, neck_mask)
|
161 |
+
arm_mask = cv2.dilate(np.logical_or(im_arms_left, im_arms_right).astype('float32'), np.ones((5, 5), np.uint8), iterations=4)
|
162 |
parse_mask += np.logical_or(parse_mask, arm_mask)
|
163 |
|
164 |
parse_mask = np.logical_and(parser_mask_changeable, np.logical_not(parse_mask))
|