patrickligardes commited on
Commit
1f866ad
β€’
1 Parent(s): 19945e3

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +12 -5
utils_mask.py CHANGED
@@ -77,25 +77,32 @@ 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
  if category == 'dresses':
81
  # Initial dress mask for the upper body
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
-
87
  # Create a mask for the legs (including skirts and pants)
88
  parse_mask_legs = np.logical_or.reduce((parse_array == label_map["skirt"],
89
  parse_array == label_map["pants"],
90
  parse_array == label_map["left_leg"],
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)
101
  parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \
 
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 = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
84
+
 
 
 
85
  # Create a mask for the legs (including skirts and pants)
86
  parse_mask_legs = np.logical_or.reduce((parse_array == label_map["skirt"],
87
  parse_array == label_map["pants"],
88
  parse_array == label_map["left_leg"],
89
  parse_array == label_map["right_leg"])).astype(np.float32)
90
+
91
  # Dilate the leg mask to ensure coverage and fill gaps
92
  parse_mask_legs = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
93
+
94
+ # Include legs mask in the fixed lower clothing mask
95
+ parser_mask_fixed_lower_cloth = np.logical_or(parse_mask_legs,
96
+ (parse_array == label_map["skirt"]).astype(np.float32) +
97
+ (parse_array == label_map["pants"]).astype(np.float32)).astype(np.float32)
98
+
99
+ # Add the fixed lower clothing mask to parser_mask_fixed
100
+ parser_mask_fixed += parser_mask_fixed_lower_cloth
101
 
102
  # Combine the upper body mask with the leg mask
103
  parse_mask = np.maximum(parse_mask_upper, parse_mask_legs)
104
 
105
+
106
  elif category == 'upper_body':
107
  parse_mask = (parse_array == 4).astype(np.float32) + (parse_array == 7).astype(np.float32)
108
  parser_mask_fixed_lower_cloth = (parse_array == label_map["skirt"]).astype(np.float32) + \