Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -171,10 +171,19 @@ def get_mesh(image: Image.Image, depth, image_path: str, foreground: np.ndarray)
|
|
| 171 |
|
| 172 |
depth_image_normalized = ((depth_image_resized - depth_image_resized.min()) /
|
| 173 |
(depth_image_resized.max() - depth_image_resized.min()) * 255.0).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
#
|
| 177 |
-
depth_o3d = o3d.geometry.Image(
|
| 178 |
image_o3d = o3d.geometry.Image(foreground)
|
| 179 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 180 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|
|
|
|
| 171 |
|
| 172 |
depth_image_normalized = ((depth_image_resized - depth_image_resized.min()) /
|
| 173 |
(depth_image_resized.max() - depth_image_resized.min()) * 255.0).astype(np.float32)
|
| 174 |
+
# Apply edge detection to enhance the subject’s edges
|
| 175 |
+
sobel_x = sobel(depth_image_normalized, axis=0)
|
| 176 |
+
sobel_y = sobel(depth_image_normalized, axis=1)
|
| 177 |
+
gradient_magnitude = np.hypot(sobel_x, sobel_y)
|
| 178 |
|
| 179 |
+
# Generate an edge mask that captures only strong edges
|
| 180 |
+
edge_mask = gradient_magnitude < (gradient_magnitude.max() * edge_strength)
|
| 181 |
+
|
| 182 |
+
# Keep depth values only within the edge mask area (isolating the main subject)
|
| 183 |
+
depth_image_sharpened = np.where(edge_mask, depth_image_normalized, 0)
|
| 184 |
|
| 185 |
+
# Create Open3D RGBD image
|
| 186 |
+
depth_o3d = o3d.geometry.Image(depth_image_sharpened)
|
| 187 |
image_o3d = o3d.geometry.Image(foreground)
|
| 188 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 189 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|