codic commited on
Commit
2ae1333
·
verified ·
1 Parent(s): 69a63e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -39,8 +39,9 @@ def process_image(image_path, depth_map_path=None):
39
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
40
  depth_image = np.array(depth_image)
41
 
42
- # Normalize depth image to [0, 1] before conversion
43
  depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
 
44
  else:
45
  encoding = feature_extractor(foreground, return_tensors="pt")
46
  with torch.no_grad():
@@ -54,9 +55,10 @@ def process_image(image_path, depth_map_path=None):
54
  align_corners=False,
55
  ).squeeze()
56
 
57
- # Normalize prediction to [0, 1] range
58
  depth_image = prediction.cpu().numpy()
59
  depth_image = depth_image / np.max(depth_image)
 
60
 
61
  # Convert to 8-bit unsigned integer after normalizing
62
  depth_image = img_as_ubyte(depth_image)
@@ -86,7 +88,6 @@ def process_image(image_path, depth_map_path=None):
86
  img = Image.fromarray(depth_image)
87
  return [img, gltf_path, gltf_path]
88
 
89
-
90
  def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
91
  depth_image_resized = np.array(
92
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
 
39
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
40
  depth_image = np.array(depth_image)
41
 
42
+ # Normalize depth image to [0, 1] range and clip
43
  depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
44
+ depth_image = np.clip(depth_image, 0, 1)
45
  else:
46
  encoding = feature_extractor(foreground, return_tensors="pt")
47
  with torch.no_grad():
 
55
  align_corners=False,
56
  ).squeeze()
57
 
58
+ # Normalize prediction to [0, 1] range and clip
59
  depth_image = prediction.cpu().numpy()
60
  depth_image = depth_image / np.max(depth_image)
61
+ depth_image = np.clip(depth_image, 0, 1)
62
 
63
  # Convert to 8-bit unsigned integer after normalizing
64
  depth_image = img_as_ubyte(depth_image)
 
88
  img = Image.fromarray(depth_image)
89
  return [img, gltf_path, gltf_path]
90
 
 
91
  def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
92
  depth_image_resized = np.array(
93
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)