patrickligardes commited on
Commit
adfb1f7
ยท
verified ยท
1 Parent(s): 13c380f

Update utils_mask.py

Browse files
Files changed (1) hide show
  1. utils_mask.py +16 -13
utils_mask.py CHANGED
@@ -78,25 +78,28 @@ def get_mask_location(model_type, category, model_parse: Image.Image, keypoint:
78
  arms_right = (parse_array == 15).astype(np.float32)
79
 
80
  if category == 'dresses':
81
- parse_mask = (parse_array == 7).astype(np.float32) + \
82
- (parse_array == 4).astype(np.float32) + \
83
- (parse_array == 5).astype(np.float32) + \
84
- (parse_array == 6).astype(np.float32)
85
 
86
- parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
 
 
 
87
 
88
- # Create a separate mask for the leg parts
89
- leg_mask = (parse_array == 12).astype(np.float32) + \
90
- (parse_array == 13).astype(np.float32)
91
 
92
  # Fill gaps between legs
93
- leg_gap_filled = cv2.dilate(leg_mask.astype(np.uint8), np.ones((10, 10), np.uint8), iterations=10)
 
 
 
 
94
 
95
- # Ensure the filled leg gaps do not affect the upper body
96
- leg_gap_filled = np.logical_and(leg_gap_filled, leg_mask).astype(np.float32)
97
 
98
- # Add the filled leg gaps to the parse_mask
99
- parse_mask += leg_gap_filled
100
 
101
 
102
  elif category == 'upper_body':
 
78
  arms_right = (parse_array == 15).astype(np.float32)
79
 
80
  if category == 'dresses':
81
+ # Initial dress mask without legs
82
+ parse_mask_upper = (parse_array == 7).astype(np.float32) + \
83
+ (parse_array == 4).astype(np.float32) + \
84
+ (parse_array == 5).astype(np.float32)
85
 
86
+ # Create a separate mask for the legs
87
+ parse_mask_legs = (parse_array == 12).astype(np.float32) + \
88
+ (parse_array == 13).astype(np.float32) + \
89
+ (parse_array == 6).astype(np.float32)
90
 
91
+ parser_mask_changeable += np.logical_and(parse_array, np.logical_not(parser_mask_fixed))
 
 
92
 
93
  # Fill gaps between legs
94
+ leg_mask_filled = cv2.dilate(parse_mask_legs.astype(np.uint8), np.ones((6, 6), np.uint8), iterations=6)
95
+ leg_mask_filled = cv2.erode(leg_mask_filled, np.ones((6, 6), np.uint8), iterations=6) # Optional: Erode back to original size
96
+
97
+ # Combine filled leg mask with upper body mask
98
+ parse_mask = np.maximum(parse_mask_upper, leg_mask_filled)
99
 
100
+ # Final dilation to ensure there are no small gaps
101
+ parse_mask = cv2.dilate(parse_mask.astype(np.uint8), np.ones((5, 5), np.uint8), iterations=5)
102
 
 
 
103
 
104
 
105
  elif category == 'upper_body':