codic commited on
Commit
c80f691
·
verified ·
1 Parent(s): 98ea7b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -16,6 +16,25 @@ from rembg import remove
16
  feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
17
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Function to inpaint the background
20
 
21
  def inpaint_background(image, mask):
@@ -58,24 +77,7 @@ def inpaint_background(image, mask):
58
  return inpainted_image
59
 
60
  # Function to inpaint the background
61
- def inpaint_background(image, mask):
62
- """
63
- Inpaint the background of the image using the given mask.
64
-
65
- Args:
66
- image (np.ndarray): The input image.
67
- mask (np.ndarray): The mask indicating the area to inpaint.
68
-
69
- Returns:
70
- np.ndarray: The inpainted image.
71
- """
72
- # Ensure the mask is binary (0 and 255)
73
- mask_binary = (mask * 255).astype(np.uint8)
74
-
75
- # Inpaint the image using the mask
76
- inpainted_image = cv2.inpaint(image.astype(np.uint8), mask_binary, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
77
-
78
- return inpainted_image
79
  def process_image(image_path, depth_map_path=None):
80
  image_path = Path(image_path)
81
  image_raw = Image.open(image_path).convert("RGB")
 
16
  feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
17
  model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
18
 
19
+
20
+ def normalize_depth_image(depth_image):
21
+ # Ensure depth_image is of type float32
22
+ depth_image = depth_image.astype(np.float32)
23
+
24
+ # Normalize depth values to the range [0, 1]
25
+ min_val = np.min(depth_image)
26
+ max_val = np.max(depth_image)
27
+
28
+ # Avoid division by zero
29
+ if max_val - min_val > 0:
30
+ depth_image_normalized = (depth_image - min_val) / (max_val - min_val)
31
+ else:
32
+ depth_image_normalized = depth_image - min_val # Handle the case where all values are the same
33
+
34
+ return depth_image_normalized
35
+
36
+
37
+
38
  # Function to inpaint the background
39
 
40
  def inpaint_background(image, mask):
 
77
  return inpainted_image
78
 
79
  # Function to inpaint the background
80
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def process_image(image_path, depth_map_path=None):
82
  image_path = Path(image_path)
83
  image_raw = Image.open(image_path).convert("RGB")