Update app.py
Browse files
app.py
CHANGED
|
@@ -65,12 +65,12 @@ def process_image(image_path, depth_map_path=None):
|
|
| 65 |
mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1)
|
| 66 |
|
| 67 |
# Create an edge mask to detect the edges of the main subject
|
| 68 |
-
edges = cv2.Canny(img_as_ubyte(mask), threshold1=
|
| 69 |
-
edges_dilated = cv2.dilate(edges, np.ones((5, 5), np.uint8), iterations=
|
| 70 |
|
| 71 |
# Erode the depth map more precisely around edges to remove any background extensions
|
| 72 |
kernel = np.ones((7, 7), np.uint8)
|
| 73 |
-
depth_eroded = cv2.erode(depth_image * mask, kernel, iterations=
|
| 74 |
|
| 75 |
# Apply the edge-aware mask to limit depth to the main subject only
|
| 76 |
depth_subject_only = np.where(edges_dilated == 0, depth_eroded, 0)
|
|
|
|
| 65 |
mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1)
|
| 66 |
|
| 67 |
# Create an edge mask to detect the edges of the main subject
|
| 68 |
+
edges = cv2.Canny(img_as_ubyte(mask), threshold1=100, threshold2=200)
|
| 69 |
+
edges_dilated = cv2.dilate(edges, np.ones((5, 5), np.uint8), iterations=3)
|
| 70 |
|
| 71 |
# Erode the depth map more precisely around edges to remove any background extensions
|
| 72 |
kernel = np.ones((7, 7), np.uint8)
|
| 73 |
+
depth_eroded = cv2.erode(depth_image * mask, kernel, iterations=4)
|
| 74 |
|
| 75 |
# Apply the edge-aware mask to limit depth to the main subject only
|
| 76 |
depth_subject_only = np.where(edges_dilated == 0, depth_eroded, 0)
|