Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,24 @@ from rembg import remove
|
|
| 16 |
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
| 17 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def process_image(image_path, depth_map_path=None):
|
| 20 |
image_path = Path(image_path)
|
| 21 |
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 |
+
# Normalization function
|
| 21 |
+
def normalize_depth_image(depth_image):
|
| 22 |
+
# Ensure depth_image is of type float32
|
| 23 |
+
depth_image = depth_image.astype(np.float32)
|
| 24 |
+
|
| 25 |
+
# Normalize depth values to the range [0, 1]
|
| 26 |
+
min_val = np.min(depth_image)
|
| 27 |
+
max_val = np.max(depth_image)
|
| 28 |
+
|
| 29 |
+
# Avoid division by zero
|
| 30 |
+
if max_val - min_val > 0:
|
| 31 |
+
depth_image_normalized = (depth_image - min_val) / (max_val - min_val)
|
| 32 |
+
else:
|
| 33 |
+
depth_image_normalized = depth_image - min_val # Handle the case where all values are the same
|
| 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")
|