Spaces:
Running
on
Zero
Running
on
Zero
patrickligardes
commited on
Commit
β’
cd6cc3e
1
Parent(s):
42200a1
Update utils_mask.py
Browse files- utils_mask.py +20 -26
utils_mask.py
CHANGED
@@ -24,11 +24,11 @@ label_map = {
|
|
24 |
}
|
25 |
|
26 |
def extend_arm_mask(wrist, elbow, scale):
|
27 |
-
|
28 |
-
|
29 |
|
30 |
def hole_fill(img):
|
31 |
-
img = np.pad(img[1:-1, 1:-1], pad_width=1, mode='constant', constant_values=0)
|
32 |
img_copy = img.copy()
|
33 |
mask = np.zeros((img.shape[0] + 2, img.shape[1] + 2), dtype=np.uint8)
|
34 |
|
@@ -51,7 +51,7 @@ def refine_mask(mask):
|
|
51 |
|
52 |
return refine_mask
|
53 |
|
54 |
-
def get_mask_location(model_type, category, model_parse: Image.Image, keypoint: dict, width=384,
|
55 |
im_parse = model_parse.resize((width, height), Image.NEAREST)
|
56 |
parse_array = np.array(im_parse)
|
57 |
|
@@ -85,27 +85,21 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
85 |
|
86 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
(parse_array ==
|
98 |
-
(parse_array ==
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
104 |
-
|
105 |
-
# Fill gaps in legs
|
106 |
-
leg_mask = cv2.dilate(parse_mask.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=5)
|
107 |
-
parse_mask += leg_mask
|
108 |
-
|
109 |
else:
|
110 |
raise NotImplementedError
|
111 |
|
@@ -170,4 +164,4 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
170 |
mask = Image.fromarray(inpaint_mask.astype(np.uint8) * 255)
|
171 |
mask_gray = Image.fromarray(inpaint_mask.astype(np.uint8) * 127)
|
172 |
|
173 |
-
return mask, mask_gray
|
|
|
24 |
}
|
25 |
|
26 |
def extend_arm_mask(wrist, elbow, scale):
|
27 |
+
wrist = elbow + scale * (wrist - elbow)
|
28 |
+
return wrist
|
29 |
|
30 |
def hole_fill(img):
|
31 |
+
img = np.pad(img[1:-1, 1:-1], pad_width = 1, mode = 'constant', constant_values=0)
|
32 |
img_copy = img.copy()
|
33 |
mask = np.zeros((img.shape[0] + 2, img.shape[1] + 2), dtype=np.uint8)
|
34 |
|
|
|
51 |
|
52 |
return refine_mask
|
53 |
|
54 |
+
def get_mask_location(model_type, category, model_parse: Image.Image, keypoint: dict, width=384,height=512):
|
55 |
im_parse = model_parse.resize((width, height), Image.NEAREST)
|
56 |
parse_array = np.array(im_parse)
|
57 |
|
|
|
85 |
|
86 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
87 |
|
88 |
+
elif category == 'upper_body':
|
89 |
+
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
90 |
+
parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
|
91 |
+
(parse_array == label_map["pants"]).astype(np.float32)
|
92 |
+
parser_mask_fixed += parser_mask_fixed_lower_cloth
|
93 |
+
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
94 |
+
elif category == 'lower_body':
|
95 |
+
parse_mask = (parse_array == 6).astype(np.float32) + \
|
96 |
+
(parse_array == 12).astype(np.float32) + \
|
97 |
+
(parse_array == 13).astype(np.float32) + \
|
98 |
+
(parse_array == 5).astype(np.float32)
|
99 |
+
parser_mask_fixed += (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
|
100 |
+
(parse_array == 14).astype(np.float32) + \
|
101 |
+
(parse_array == 15).astype(np.float32)
|
102 |
+
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
else:
|
104 |
raise NotImplementedError
|
105 |
|
|
|
164 |
mask = Image.fromarray(inpaint_mask.astype(np.uint8) * 255)
|
165 |
mask_gray = Image.fromarray(inpaint_mask.astype(np.uint8) * 127)
|
166 |
|
167 |
+
return mask, mask_gray
|