Update app.py
Browse files
app.py
CHANGED
|
@@ -39,8 +39,8 @@ 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 |
depth_image = (depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
|
| 43 |
-
depth_image = img_as_ubyte(depth_image)
|
| 44 |
else:
|
| 45 |
encoding = feature_extractor(foreground, return_tensors="pt")
|
| 46 |
with torch.no_grad():
|
|
@@ -53,7 +53,13 @@ def process_image(image_path, depth_map_path=None):
|
|
| 53 |
mode="bicubic",
|
| 54 |
align_corners=False,
|
| 55 |
).squeeze()
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Apply Gaussian smoothing to depth map
|
| 59 |
depth_image = gaussian(depth_image, sigma=0.8, preserve_range=True)
|
|
|
|
| 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():
|
|
|
|
| 53 |
mode="bicubic",
|
| 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)
|
| 63 |
|
| 64 |
# Apply Gaussian smoothing to depth map
|
| 65 |
depth_image = gaussian(depth_image, sigma=0.8, preserve_range=True)
|