codic commited on
Commit
5b99b62
·
verified ·
1 Parent(s): 8856613

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -23,12 +23,17 @@ def process_image(image_path, depth_map_path=None):
23
 
24
  # Generate or load depth map
25
  if depth_map_path:
26
- # Load and resize depth map to match the RGB image size
27
- depth_image_raw = Image.open(depth_map_path)
28
- depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
29
- depth_image = np.array(depth_image)
30
-
31
- # Normalize depth map if needed
 
 
 
 
 
32
  depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
33
  depth_image = (depth_image * 255).astype('uint8')
34
  else:
@@ -49,7 +54,7 @@ def process_image(image_path, depth_map_path=None):
49
  depth_rgba = Image.fromarray(depth_image).convert("RGBA").resize(image.size)
50
  image_rgba = image.convert("RGBA")
51
 
52
- # Composite depth onto the RGB image background without purple tint
53
  bg_with_depth = Image.alpha_composite(image_rgba, depth_rgba)
54
 
55
  try:
@@ -57,7 +62,6 @@ def process_image(image_path, depth_map_path=None):
57
  gltf_path = create_3d_obj(np.array(image), depth_image, image_path)
58
  return [Image.fromarray(depth_image), gltf_path, gltf_path]
59
  except Exception as e:
60
- # Optionally, handle specific reconstruction issues
61
  print("Error reconstructing 3D model:", e)
62
  raise Exception("Error reconstructing 3D model")
63
 
 
23
 
24
  # Generate or load depth map
25
  if depth_map_path:
26
+ # Check if depth map is in .npy format
27
+ if depth_map_path.endswith(".npy"):
28
+ # Load the depth map directly as a NumPy array
29
+ depth_image = np.load(depth_map_path)
30
+ else:
31
+ # Load and resize non-npy depth map to match the RGB image size
32
+ depth_image_raw = Image.open(depth_map_path)
33
+ depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
34
+ depth_image = np.array(depth_image)
35
+
36
+ # Normalize depth map to 0–255 range if needed
37
  depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
38
  depth_image = (depth_image * 255).astype('uint8')
39
  else:
 
54
  depth_rgba = Image.fromarray(depth_image).convert("RGBA").resize(image.size)
55
  image_rgba = image.convert("RGBA")
56
 
57
+ # Composite depth onto the RGB image background
58
  bg_with_depth = Image.alpha_composite(image_rgba, depth_rgba)
59
 
60
  try:
 
62
  gltf_path = create_3d_obj(np.array(image), depth_image, image_path)
63
  return [Image.fromarray(depth_image), gltf_path, gltf_path]
64
  except Exception as e:
 
65
  print("Error reconstructing 3D model:", e)
66
  raise Exception("Error reconstructing 3D model")
67