codic commited on
Commit
ef3100a
·
verified ·
1 Parent(s): 27495ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -120,12 +120,12 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
120
  sobel_y = sobel(depth_image_normalized, axis=1)
121
  gradient_magnitude = np.hypot(sobel_x, sobel_y)
122
 
123
- # Threshold the gradient magnitude to detect edges
124
  edge_mask = gradient_magnitude > (gradient_magnitude.max() * edge_strength)
 
125
 
126
- # Apply the edge mask to the depth map, removing blur around edges
127
- depth_image_sharpened = np.copy(depth_image_normalized)
128
- depth_image_sharpened[~edge_mask] = 0 # Remove non-edge areas by setting them to 0 (background)
129
 
130
  # Create Open3D RGBD image
131
  depth_o3d = o3d.geometry.Image(depth_image_sharpened)
 
120
  sobel_y = sobel(depth_image_normalized, axis=1)
121
  gradient_magnitude = np.hypot(sobel_x, sobel_y)
122
 
123
+ # Threshold the gradient magnitude to detect edges, then smooth out with morphological filtering
124
  edge_mask = gradient_magnitude > (gradient_magnitude.max() * edge_strength)
125
+ edge_mask = np.logical_and(depth_image_normalized > 10, edge_mask) # Ensure main subject is prioritized
126
 
127
+ # Apply the edge mask to the depth map, keeping main subject depth values
128
+ depth_image_sharpened = np.where(edge_mask, depth_image_normalized, 0)
 
129
 
130
  # Create Open3D RGBD image
131
  depth_o3d = o3d.geometry.Image(depth_image_sharpened)