Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,21 +46,21 @@ 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 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
|
| 66 |
# Apply the mask (preserve only selected regions)
|
|
|
|
| 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)
|