codic commited on
Commit
b00c2bd
·
verified ·
1 Parent(s): cc4b364

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -66,15 +66,15 @@ def process_image(image_path, depth_map_path=None):
66
 
67
  # Step 2: Edge-preserving filter (Enhance small structures)
68
  depth_image = cv2.edgePreservingFilter(
69
- (depth_image_cleaned * 255).astype(np.uint8), flags=1, sigma_s=13, sigma_r=0.3
70
  )
71
  depth_image = depth_image.astype(np.float32) / 255 # Normalize back to [0, 1]
72
 
73
  # Step 3: Smooth depth map with Gaussian filter
74
- depth_image = cv2.GaussianBlur(depth_image, (5, 5), sigmaX=3, sigmaY=3)
75
 
76
  # Step 4: Bilateral filter for detail preservation
77
- depth_image = cv2.bilateralFilter((depth_image * 255).astype(np.uint8), 7, 60, 60).astype(np.float32) / 255
78
 
79
  # Step 5: Resize the depth map to match the foreground size
80
  depth_image = cv2.resize(depth_image, (foreground.size[0], foreground.size[1]), interpolation=cv2.INTER_LANCZOS4) # High-quality interpolation for resizing
@@ -161,7 +161,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
161
 
162
  # Create Poisson mesh using main subject's isolated depth
163
  mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
164
- pcd, depth=depth, width=0, scale=2, linear_fit=True
165
  )
166
  # Remove low-density artifacts
167
  density_threshold = np.quantile(np.asarray(densities), 0.06) # Adjust quantile as needed
@@ -170,7 +170,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
170
 
171
 
172
  # Simplify with smaller voxel size for more detail
173
- voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 6200
174
  mesh = mesh_raw.simplify_vertex_clustering(
175
  voxel_size=voxel_size,
176
  contraction=o3d.geometry.SimplificationContraction.Average,
 
66
 
67
  # Step 2: Edge-preserving filter (Enhance small structures)
68
  depth_image = cv2.edgePreservingFilter(
69
+ (depth_image_cleaned * 255).astype(np.uint8), flags=1, sigma_s=10, sigma_r=0.2
70
  )
71
  depth_image = depth_image.astype(np.float32) / 255 # Normalize back to [0, 1]
72
 
73
  # Step 3: Smooth depth map with Gaussian filter
74
+ depth_image = cv2.GaussianBlur(depth_image, (3, 3), sigmaX=1.5, sigmaY=1.5)
75
 
76
  # Step 4: Bilateral filter for detail preservation
77
+ depth_image = cv2.bilateralFilter((depth_image * 255).astype(np.uint8), 5, 50, 50).astype(np.float32) / 255
78
 
79
  # Step 5: Resize the depth map to match the foreground size
80
  depth_image = cv2.resize(depth_image, (foreground.size[0], foreground.size[1]), interpolation=cv2.INTER_LANCZOS4) # High-quality interpolation for resizing
 
161
 
162
  # Create Poisson mesh using main subject's isolated depth
163
  mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
164
+ pcd, depth=depth, width=0, scale=4, linear_fit=True
165
  )
166
  # Remove low-density artifacts
167
  density_threshold = np.quantile(np.asarray(densities), 0.06) # Adjust quantile as needed
 
170
 
171
 
172
  # Simplify with smaller voxel size for more detail
173
+ voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 7200
174
  mesh = mesh_raw.simplify_vertex_clustering(
175
  voxel_size=voxel_size,
176
  contraction=o3d.geometry.SimplificationContraction.Average,