Spaces:
Running
on
Zero
Running
on
Zero
Update utils_mask.py
Browse files- utils_mask.py +9 -5
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
|
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,height=512):
|
55 |
im_parse = model_parse.resize((width, height), Image.NEAREST)
|
56 |
parse_array = np.array(im_parse)
|
57 |
|
@@ -84,6 +84,10 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
84 |
(parse_array == 6).astype(np.float32)
|
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)
|
@@ -164,4 +168,4 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
|
|
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
|
|
|
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 |
|
|
|
84 |
(parse_array == 6).astype(np.float32)
|
85 |
|
86 |
parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
|
87 |
+
|
88 |
+
# Include leg parts for gap filling
|
89 |
+
parse_mask += (parse_array == 12).astype(np.float32) + \
|
90 |
+
(parse_array == 13).astype(np.float32)
|
91 |
|
92 |
elif category == 'upper_body':
|
93 |
parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
|
|
|
168 |
mask = Image.fromarray(inpaint_mask.astype(np.uint8) * 255)
|
169 |
mask_gray = Image.fromarray(inpaint_mask.astype(np.uint8) * 127)
|
170 |
|
171 |
+
return mask, mask_gray
|