codic commited on
Commit
ffcd43d
·
verified ·
1 Parent(s): 3984d08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -23,10 +23,16 @@ def process_image(image_path, depth_map_path=None):
23
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
24
  depth_image = np.array(depth_image)
25
 
26
- # Invert the depth map if needed (for MiDaS depth maps)
27
- depth_image = np.max(depth_image) - depth_image
 
 
 
 
 
 
28
  else:
29
- # Automatically generate the depth map using the model
30
  encoding = feature_extractor(image, return_tensors="pt")
31
  with torch.no_grad():
32
  outputs = model(**encoding)
 
23
  depth_image = depth_image_raw.resize(image.size, Image.Resampling.NEAREST)
24
  depth_image = np.array(depth_image)
25
 
26
+ # Adjust the depth map based on the Depth-Anything-V2 format
27
+ # Normalize depth if needed (assuming values are not scaled to 0-255)
28
+ depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
29
+ depth_image = (depth_image * 255).astype('uint8')
30
+
31
+ # Optionally invert the depth map if it's inverse (like MiDaS)
32
+ # depth_image = np.max(depth_image) - depth_image
33
+
34
  else:
35
+ # Automatically generate the depth map using the model (if no depth map provided)
36
  encoding = feature_extractor(image, return_tensors="pt")
37
  with torch.no_grad():
38
  outputs = model(**encoding)