devendergarg14 commited on
Commit
ccaf896
·
verified ·
1 Parent(s): 79a0fd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -46,18 +46,22 @@ def process_image(image, categories_to_hide):
46
 
47
  # Expand clothing boundaries if clothes are in `categories_to_hide`
48
  if "Clothes" in categories_to_hide:
49
- clothing_mask = np.isin(mask_data, grouped_mapping["Clothes"]).astype(np.uint8)
50
 
51
- # Determine kernel size (3% of the smaller image dimension)
52
- height, width = clothing_mask.shape
53
- kernel_size = max(1, int(0.02 * min(height, width))) # Ensure at least 1 pixel
54
- kernel = np.ones((kernel_size, kernel_size), np.uint8)
55
 
56
- # Dilate the clothing mask
57
- dilated_clothing_mask = cv2.dilate(clothing_mask, kernel, iterations=1)
 
 
 
 
 
 
58
 
59
- # Update mask_combined with the expanded clothing mask
60
- mask_combined |= (dilated_clothing_mask == 1)
61
 
62
  # Apply the mask (preserve only selected regions)
63
  transparent_image[mask_combined] = image_array[mask_combined]
 
46
 
47
  # Expand clothing boundaries if clothes are in `categories_to_hide`
48
  if "Clothes" in categories_to_hide:
49
+ clothing_mask = np.isin(mask_data, grouped_mapping["Clothes"]).astype(np.uint8)
50
 
51
+ # Determine kernel size (2% of the smaller image dimension)
52
+ height, width = clothing_mask.shape
53
+ kernel_size = max(1, int(0.02 * min(height, width))) # Ensure at least 1 pixel
54
+ kernel = np.ones((kernel_size, kernel_size), np.uint8)
55
 
56
+ # **Step 1: Fill gaps using Morphological Closing (Dilation + Erosion)**
57
+ closed_clothing_mask = cv2.morphologyEx(clothing_mask, cv2.MORPH_CLOSE, kernel, iterations=1)
58
+
59
+ # **Step 2: Expand clothing boundary using Dilation**
60
+ dilated_clothing_mask = cv2.dilate(closed_clothing_mask, kernel, iterations=1)
61
+
62
+ # Update mask_combined with the expanded clothing mask
63
+ mask_combined |= (dilated_clothing_mask == 1)
64
 
 
 
65
 
66
  # Apply the mask (preserve only selected regions)
67
  transparent_image[mask_combined] = image_array[mask_combined]