codic commited on
Commit
eb4395c
·
verified ·
1 Parent(s): e2ae7ba

Only main subject

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -78,18 +78,18 @@ def process_image(image_path, depth_map_path=None):
78
  # Blend depth_image with mask_blurred_resized for smoother transition
79
  blended_depth_image = cv2.addWeighted(depth_image, 0.8, mask_blurred_resized, 0.2, 0)
80
 
81
- # Inpaint background where main subject was removed
82
- background = remove(image_raw, only_mask=True)
83
- background = cv2.cvtColor(np.array(background), cv2.COLOR_GRAY2BGR)
84
- background_inpainted = cv2.inpaint(np.array(image_raw), background[:, :, 0], inpaintRadius=3, flags=cv2.INPAINT_TELEA)
85
 
86
  try:
87
- gltf_path = create_3d_obj(np.array(foreground), blended_depth_image, background_inpainted, image_path)
88
  img = Image.fromarray(blended_depth_image)
89
  return [img, gltf_path, gltf_path]
90
  except Exception as e:
91
  print(f"Error with default depth: {str(e)}. Retrying with a shallower depth.")
92
- gltf_path = create_3d_obj(np.array(foreground), blended_depth_image, background_inpainted, image_path, depth=9)
93
  img = Image.fromarray(blended_depth_image)
94
  return [img, gltf_path, gltf_path]
95
 
@@ -130,6 +130,7 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
130
  pcd, depth=depth, width=0, scale=1.2, linear_fit=True
131
  )
132
 
 
133
  voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 400
134
  mesh = mesh_raw.simplify_vertex_clustering(
135
  voxel_size=voxel_size,
@@ -149,7 +150,6 @@ description = "Upload an image and optionally a depth map (in .npy or image form
149
 
150
  examples = [["examples/" + img] for img in os.listdir("examples/")]
151
 
152
-
153
  iface = gr.Interface(
154
  fn=process_image,
155
  inputs=[
@@ -167,4 +167,4 @@ iface = gr.Interface(
167
  allow_flagging="never",
168
  cache_examples=False,
169
  )
170
- iface.launch(debug=True, show_api=True, share=True)
 
78
  # Blend depth_image with mask_blurred_resized for smoother transition
79
  blended_depth_image = cv2.addWeighted(depth_image, 0.8, mask_blurred_resized, 0.2, 0)
80
 
81
+ # Commenting out the background inpainting section
82
+ # background = remove(image_raw, only_mask=True)
83
+ # background = cv2.cvtColor(np.array(background), cv2.COLOR_GRAY2BGR)
84
+ # background_inpainted = cv2.inpaint(np.array(image_raw), background[:, :, 0], inpaintRadius=3, flags=cv2.INPAINT_TELEA)
85
 
86
  try:
87
+ gltf_path = create_3d_obj(np.array(foreground), blended_depth_image, None, image_path)
88
  img = Image.fromarray(blended_depth_image)
89
  return [img, gltf_path, gltf_path]
90
  except Exception as e:
91
  print(f"Error with default depth: {str(e)}. Retrying with a shallower depth.")
92
+ gltf_path = create_3d_obj(np.array(foreground), blended_depth_image, None, image_path, depth=9)
93
  img = Image.fromarray(blended_depth_image)
94
  return [img, gltf_path, gltf_path]
95
 
 
130
  pcd, depth=depth, width=0, scale=1.2, linear_fit=True
131
  )
132
 
133
+ # Flatten the back of the model from the zero point
134
  voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 400
135
  mesh = mesh_raw.simplify_vertex_clustering(
136
  voxel_size=voxel_size,
 
150
 
151
  examples = [["examples/" + img] for img in os.listdir("examples/")]
152
 
 
153
  iface = gr.Interface(
154
  fn=process_image,
155
  inputs=[
 
167
  allow_flagging="never",
168
  cache_examples=False,
169
  )
170
+ iface.launch(debug=True, show_api=True, share=True)