Spaces:
Sleeping
Sleeping
bgREM updated
Browse files
app.py
CHANGED
|
@@ -119,7 +119,22 @@ def _process_saree_core(base_image: Image.Image, pattern_image: Image.Image):
|
|
| 119 |
# Get RGBA from bgrem
|
| 120 |
result_no_bg = bgrem_remove(base_bytes)
|
| 121 |
mask_img = Image.open(BytesIO(result_no_bg)).convert("RGBA")
|
|
|
|
|
|
|
| 122 |
mask_alpha = np.array(mask_img)[:, :, 3].astype(np.float32) / 255.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Feather edges for smoother blending
|
| 125 |
mask_blurred = cv2.GaussianBlur((mask_alpha * 255).astype(np.uint8), (15, 15), sigmaX=5, sigmaY=5)
|
|
|
|
| 119 |
# Get RGBA from bgrem
|
| 120 |
result_no_bg = bgrem_remove(base_bytes)
|
| 121 |
mask_img = Image.open(BytesIO(result_no_bg)).convert("RGBA")
|
| 122 |
+
|
| 123 |
+
# Extract alpha and clean edges
|
| 124 |
mask_alpha = np.array(mask_img)[:, :, 3].astype(np.float32) / 255.0
|
| 125 |
+
|
| 126 |
+
# --- NEW FIXES ---
|
| 127 |
+
# 1. Slightly shrink the mask to remove halos
|
| 128 |
+
kernel = np.ones((3, 3), np.uint8)
|
| 129 |
+
mask_binary = (mask_alpha > 0.05).astype(np.uint8) * 255
|
| 130 |
+
mask_eroded = cv2.erode(mask_binary, kernel, iterations=1)
|
| 131 |
+
|
| 132 |
+
# 2. Feather edges to smooth transition
|
| 133 |
+
mask_blurred = cv2.GaussianBlur(mask_eroded, (15, 15), sigmaX=3, sigmaY=3)
|
| 134 |
+
|
| 135 |
+
# 3. Re-normalize
|
| 136 |
+
mask_blurred = mask_blurred.astype(np.float32) / 255.0
|
| 137 |
+
|
| 138 |
|
| 139 |
# Feather edges for smoother blending
|
| 140 |
mask_blurred = cv2.GaussianBlur((mask_alpha * 255).astype(np.uint8), (15, 15), sigmaX=5, sigmaY=5)
|