patrickligardes commited on
Commit
3f9e979
β€’
1 Parent(s): b7a4430

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +9 -13
utils_mask.py CHANGED
@@ -83,22 +83,18 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
83
  parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
84
  (parse_array == label_map["pants"]).astype(np.float32)
85
  parser_mask_fixed += parser_mask_fixed_lower_cloth
86
- parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
87
-
88
- # Create a separate mask for the legs
89
- parse_mask_legs = (parse_array == 12).astype(np.float32) + \
90
- (parse_array == 13).astype(np.float32) + \
91
- (parse_array == 6).astype(np.float32) +\
92
- (parse_array == 5).astype(np.float32)
93
 
94
- # Fill gaps between legs
95
- leg_mask_filled = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
 
 
 
96
 
97
- # Combine the filled leg mask with the upper body mask
98
- combined_mask = np.maximum(parse_mask_upper, leg_mask_filled)
99
 
100
- # Final mask without further dilation to avoid affecting the upper body mask
101
- parse_mask = combined_mask
102
 
103
  elif category == 'upper_body':
104
  parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
 
83
  parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
84
  (parse_array == label_map["pants"]).astype(np.float32)
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"]).astype(np.float32) + \
89
+ (parse_array == label_map["pants"]).astype(np.float32) + \
90
+ (parse_array == label_map["left_leg"]).astype(np.float32) + \
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)
95
 
96
+ # Combine the upper body mask with the leg mask
97
+ parse_mask = np.maximum(parse_mask_upper, parse_mask_legs)
98
 
99
  elif category == 'upper_body':
100
  parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)