Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,26 @@ from rembg import remove
|
|
| 16 |
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
| 17 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Normalization function
|
| 21 |
def normalize_depth_image(depth_image):
|
| 22 |
# Ensure depth_image is of type float32
|
|
@@ -34,6 +53,25 @@ def normalize_depth_image(depth_image):
|
|
| 34 |
|
| 35 |
return depth_image_normalized
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def process_image(image_path, depth_map_path=None):
|
| 38 |
image_path = Path(image_path)
|
| 39 |
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 |
+
# Function to inpaint the background
|
| 20 |
+
def inpaint_background(image, mask):
|
| 21 |
+
"""
|
| 22 |
+
Inpaint the background of the image using the given mask.
|
| 23 |
+
|
| 24 |
+
Args:
|
| 25 |
+
image (np.ndarray): The input image.
|
| 26 |
+
mask (np.ndarray): The mask indicating the area to inpaint.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
np.ndarray: The inpainted image.
|
| 30 |
+
"""
|
| 31 |
+
# Ensure the mask is binary (0 and 255)
|
| 32 |
+
mask_binary = (mask * 255).astype(np.uint8)
|
| 33 |
+
|
| 34 |
+
# Inpaint the image using the mask
|
| 35 |
+
inpainted_image = cv2.inpaint(image.astype(np.uint8), mask_binary, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
| 36 |
+
|
| 37 |
+
return inpainted_image
|
| 38 |
+
|
| 39 |
# Normalization function
|
| 40 |
def normalize_depth_image(depth_image):
|
| 41 |
# Ensure depth_image is of type float32
|
|
|
|
| 53 |
|
| 54 |
return depth_image_normalized
|
| 55 |
|
| 56 |
+
# Function to inpaint the background
|
| 57 |
+
def inpaint_background(image, mask):
|
| 58 |
+
"""
|
| 59 |
+
Inpaint the background of the image using the given mask.
|
| 60 |
+
|
| 61 |
+
Args:
|
| 62 |
+
image (np.ndarray): The input image.
|
| 63 |
+
mask (np.ndarray): The mask indicating the area to inpaint.
|
| 64 |
+
|
| 65 |
+
Returns:
|
| 66 |
+
np.ndarray: The inpainted image.
|
| 67 |
+
"""
|
| 68 |
+
# Ensure the mask is binary (0 and 255)
|
| 69 |
+
mask_binary = (mask * 255).astype(np.uint8)
|
| 70 |
+
|
| 71 |
+
# Inpaint the image using the mask
|
| 72 |
+
inpainted_image = cv2.inpaint(image.astype(np.uint8), mask_binary, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
| 73 |
+
|
| 74 |
+
return inpainted_image
|
| 75 |
def process_image(image_path, depth_map_path=None):
|
| 76 |
image_path = Path(image_path)
|
| 77 |
image_raw = Image.open(image_path).convert("RGB")
|