Update app.py
Browse files
app.py
CHANGED
|
@@ -79,15 +79,10 @@ def process_image(image_path, depth_map_path=None):
|
|
| 79 |
|
| 80 |
# Step 6: Create an edge-aware mask (if needed for further processing)
|
| 81 |
mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1) # Create a mask where the foreground is not black
|
| 82 |
-
|
| 83 |
# Improved edge detection for the main subject
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
upper = int(min(255, 1.33 * v))
|
| 88 |
-
edges = cv2.Canny(gray_foreground, threshold1=lower, threshold2=upper)
|
| 89 |
-
edges_dilated = cv2.dilate(edges, np.ones((7, 7), np.uint8), iterations=2)
|
| 90 |
-
edges_eroded = cv2.erode(edges_dilated, np.ones((5, 5), np.uint8), iterations=1)
|
| 91 |
|
| 92 |
# Use the refined edge mask to clean up the depth map
|
| 93 |
depth_subject_only = np.where(edges_eroded == 0, depth_image * mask, 0)
|
|
|
|
| 79 |
|
| 80 |
# Step 6: Create an edge-aware mask (if needed for further processing)
|
| 81 |
mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1) # Create a mask where the foreground is not black
|
|
|
|
| 82 |
# Improved edge detection for the main subject
|
| 83 |
+
edges = cv2.Canny(img_as_ubyte(mask), threshold1=60, threshold2=100) # Adjust thresholds for edges
|
| 84 |
+
edges_dilated = cv2.dilate(edges, np.ones((9, 9), np.uint8), iterations=4) # Larger kernel, fewer gaps
|
| 85 |
+
edges_eroded = cv2.erode(edges_dilated, np.ones((9, 9), np.uint8), iterations=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Use the refined edge mask to clean up the depth map
|
| 88 |
depth_subject_only = np.where(edges_eroded == 0, depth_image * mask, 0)
|