patrickligardes commited on
Commit
12c519f
β€’
1 Parent(s): 0c9ab31

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +15 -21
utils_mask.py CHANGED
@@ -77,29 +77,25 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
77
  arms_left = (parse_array == 14).astype(np.float32)
78
  arms_right = (parse_array == 15).astype(np.float32)
79
 
80
-
81
  if category == 'dresses':
82
- # Initial dress mask for the upper body
83
- parse_mask_upper = np.logical_or((parse_array == label_map["upper_clothes"]), (parse_array == label_map["dress"])).astype(np.float32)
84
-
 
 
 
 
 
85
 
86
- # Create a mask for the legs (including skirts and pants)
87
- parse_mask_legs = np.logical_or.reduce((parse_array == label_map["skirt"],
88
- parse_array == label_map["pants"],
89
- parse_array == label_map["left_leg"],
90
- parse_array == label_map["right_leg"])).astype(np.float32)
91
 
92
  # Dilate the leg mask to ensure coverage and fill gaps
 
 
 
 
93
  parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
94
-
95
- # Combine the upper body mask with the dilated leg mask
96
- parse_mask = np.maximum(parse_mask_upper, parse_mask_legs_dilated)
97
-
98
-
99
-
100
-
101
-
102
-
103
 
104
  elif category == 'upper_body':
105
  parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
@@ -139,7 +135,7 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
139
  size_left = [shoulder_left[0] - ARM_LINE_WIDTH // 2, shoulder_left[1] - ARM_LINE_WIDTH // 2, shoulder_left[0] + ARM_LINE_WIDTH // 2, shoulder_left[1] + ARM_LINE_WIDTH // 2]
140
  size_right = [shoulder_right[0] - ARM_LINE_WIDTH // 2, shoulder_right[1] - ARM_LINE_WIDTH // 2, shoulder_right[0] + ARM_LINE_WIDTH // 2,
141
  shoulder_right[1] + ARM_LINE_WIDTH // 2]
142
-
143
  if wrist_right[0] <= 1. and wrist_right[1] <= 1.:
144
  im_arms_right = arms_right
145
  else:
@@ -180,5 +176,3 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
180
  mask_gray = Image.fromarray(inpaint_mask.astype(np.uint8) * 127)
181
 
182
  return mask, mask_gray
183
-
184
-
 
77
  arms_left = (parse_array == 14).astype(np.float32)
78
  arms_right = (parse_array == 15).astype(np.float32)
79
 
 
80
  if category == 'dresses':
81
+ parse_mask_upper = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
82
+ parse_mask_lower = (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
+ 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
+ parse_mask = np.logical_or(parse_mask_upper, parse_mask_lower)
 
 
 
 
91
 
92
  # Dilate the leg mask to ensure coverage and fill gaps
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((6, 6), np.uint8), iterations=6)
98
+ parse_mask = np.maximum(parse_mask, parse_mask_legs_dilated)
 
 
 
 
 
 
 
 
99
 
100
  elif category == 'upper_body':
101
  parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
 
135
  size_left = [shoulder_left[0] - ARM_LINE_WIDTH // 2, shoulder_left[1] - ARM_LINE_WIDTH // 2, shoulder_left[0] + ARM_LINE_WIDTH // 2, shoulder_left[1] + ARM_LINE_WIDTH // 2]
136
  size_right = [shoulder_right[0] - ARM_LINE_WIDTH // 2, shoulder_right[1] - ARM_LINE_WIDTH // 2, shoulder_right[0] + ARM_LINE_WIDTH // 2,
137
  shoulder_right[1] + ARM_LINE_WIDTH // 2]
138
+
139
  if wrist_right[0] <= 1. and wrist_right[1] <= 1.:
140
  im_arms_right = arms_right
141
  else:
 
176
  mask_gray = Image.fromarray(inpaint_mask.astype(np.uint8) * 127)
177
 
178
  return mask, mask_gray