patrickligardes commited on
Commit
63bd92e
β€’
1 Parent(s): 1086f36

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +21 -17
utils_mask.py CHANGED
@@ -78,27 +78,31 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
78
  arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
79
 
80
  if category == 'dresses':
81
- # Upper body mask
82
- parse_mask_upper = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
83
-
84
- # Lower body masks
85
- parse_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
86
- (parse_array == label_map["pants"]).astype(np.float32)
 
 
87
  parse_mask_legs = (parse_array == 6).astype(np.float32) + \
88
  (parse_array == 12).astype(np.float32) + \
89
  (parse_array == 13).astype(np.float32) + \
90
- (parse_array == 5).astype(np.float32)
91
- parse_mask_legs_dilated = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6) # Dilate legs
92
-
93
- # Fixed and changeable masks
94
- parser_mask_fixed = (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
95
- (parse_array == label_map["left_arm"]).astype(np.float32) + \
96
- (parse_array == label_map["right_arm"]).astype(np.float32) + \
97
- parse_mask_fixed_lower_cloth # Add lower cloth to fixed mask
98
- parser_mask_changeable = np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
99
 
100
- # Combine masks (upper body + dilated legs + changeable areas)
101
- parse_mask = np.maximum.reduce([parse_mask_upper, parse_mask_legs_dilated, parser_mask_changeable.astype(np.float32)])
 
 
102
 
103
 
104
  elif category == 'upper_body':
 
78
  arms_right = (parse_array == label_map["right_arm"]).astype(np.float32)
79
 
80
  if category == 'dresses':
81
+ # Combine upper body category logic
82
+ parse_mask_upper = (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
+ parser_mask_changeable = np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
87
+
88
+ # Combine lower body category logic
89
  parse_mask_legs = (parse_array == 6).astype(np.float32) + \
90
  (parse_array == 12).astype(np.float32) + \
91
  (parse_array == 13).astype(np.float32) + \
92
+ (parse_array == 5).astype(np.float32)
93
+ parser_mask_fixed += (parse_array == label_map["upper_clothes"]).astype(np.float32) + \
94
+ (parse_array == label_map["left_arm"]).astype(np.float32) + \
95
+ (parse_array == label_map["right_arm"]).astype(np.float32)
96
+
97
+ # Include parse_mask_legs in parser_mask_changeable
98
+ parser_mask_changeable = np.logical_or(parser_mask_changeable, parse_mask_legs)
99
+
100
+ parse_mask_legs = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
101
 
102
+ # Combine the upper body mask with the leg mask
103
+ parse_mask = np.logical_and(parser_mask_changeable, np.logical_not(parse_mask))
104
+
105
+
106
 
107
 
108
  elif category == 'upper_body':