patrickligardes commited on
Commit
f4b3582
β€’
1 Parent(s): 5a19f35

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +13 -13
utils_mask.py CHANGED
@@ -76,22 +76,22 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
76
 
77
  arms_left = (parse_array == label_map["left_arm"]).astype(np.float32)
78
  arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
79
-
80
  if category == 'dresses':
81
- parse_mask_upper = (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
82
- (parse_array == label_map["dress"]).astype(np.float32)
83
-
84
- parse_mask_lower = (parse_array == label_map["skirt"]).astype(np.float32) + \
85
- (parse_array == label_map["pants"]).astype(np.float32)
86
-
87
- # Dilate the leg parts to fill gaps
88
- parse_mask_legs = (parse_array == label_map["left_leg"]).astype(np.float32) + \
89
- (parse_array == label_map["right_leg"]).astype(np.float32)
 
90
  parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
91
 
92
- # Combine upper body and dilated lower body masks
93
- parse_mask_lower = np.maximum(parse_mask_lower, parse_mask_legs_dilated)
94
- parse_mask = np.logical_or(parse_mask_upper, parse_mask_lower)
95
 
96
  elif category == 'upper_body':
97
  parse_mask = (parse_array == label_map["upper_clothes"]).astype(np.float32)
 
76
 
77
  arms_left = (parse_array == label_map["left_arm"]).astype(np.float32)
78
  arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
79
+
80
  if category == 'dresses':
81
+ # Initial dress mask for the upper body (excluding head)
82
+ parse_mask_upper = np.logical_or((parse_array == label_map["upper_clothes"]), (parse_array == label_map["dress"])).astype(np.float32)
83
+
84
+ # Create a mask for the legs (including skirts and pants)
85
+ parse_mask_legs = np.logical_or.reduce((parse_array == label_map["skirt"],
86
+ parse_array == label_map["pants"],
87
+ parse_array == label_map["left_leg"],
88
+ parse_array == label_map["right_leg"])).astype(np.float32)
89
+
90
+ # Dilate the leg mask to ensure coverage and fill gaps
91
  parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
92
 
93
+ # Combine the upper body mask with the dilated leg mask
94
+ parse_mask = np.maximum(parse_mask_upper, parse_mask_legs_dilated)
 
95
 
96
  elif category == 'upper_body':
97
  parse_mask = (parse_array == label_map["upper_clothes"]).astype(np.float32)