Update app.py
Browse files
app.py
CHANGED
|
@@ -46,39 +46,39 @@ def save_tensor_as_png(tensor: torch.Tensor, path: str, dtype: torch.dtype | Non
|
|
| 46 |
dtype = tensor.dtype
|
| 47 |
Image.fromarray(tensor.to(dtype).cpu().numpy()).save(path)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
#
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
| 83 |
def prep_for_rayst3r(img,depth_dict,mask):
|
| 84 |
H, W = img.shape[:2]
|
|
|
|
| 46 |
dtype = tensor.dtype
|
| 47 |
Image.fromarray(tensor.to(dtype).cpu().numpy()).save(path)
|
| 48 |
|
| 49 |
+
def colorize_points_with_turbo_all_dims(points, method='norm',cmap='turbo'):
|
| 50 |
+
"""
|
| 51 |
+
Assigns colors to 3D points using the 'turbo' colormap based on a scalar computed from all 3 dimensions.
|
| 52 |
+
|
| 53 |
+
Args:
|
| 54 |
+
points (np.ndarray): (N, 3) array of 3D points.
|
| 55 |
+
method (str): Method for reducing 3D point to scalar. Options: 'norm', 'pca'.
|
| 56 |
+
|
| 57 |
+
Returns:
|
| 58 |
+
np.ndarray: (N, 3) RGB colors in [0, 1].
|
| 59 |
+
"""
|
| 60 |
+
assert points.shape[1] == 3, "Input must be of shape (N, 3)"
|
| 61 |
+
|
| 62 |
+
if method == 'norm':
|
| 63 |
+
scalar = np.linalg.norm(points, axis=1)
|
| 64 |
+
elif method == 'pca':
|
| 65 |
+
# Project onto first principal component
|
| 66 |
+
mean = points.mean(axis=0)
|
| 67 |
+
centered = points - mean
|
| 68 |
+
u, s, vh = np.linalg.svd(centered, full_matrices=False)
|
| 69 |
+
scalar = centered @ vh[0] # Project onto first principal axis
|
| 70 |
+
else:
|
| 71 |
+
raise ValueError(f"Unknown method '{method}'")
|
| 72 |
+
|
| 73 |
+
# Normalize scalar to [0, 1]
|
| 74 |
+
scalar_min, scalar_max = scalar.min(), scalar.max()
|
| 75 |
+
normalized = (scalar - scalar_min) / (scalar_max - scalar_min + 1e-8)
|
| 76 |
+
|
| 77 |
+
# Apply turbo colormap
|
| 78 |
+
cmap = plt.colormaps.get_cmap(cmap)
|
| 79 |
+
colors = cmap(normalized)[:, :3] # Drop alpha
|
| 80 |
+
|
| 81 |
+
return colors
|
| 82 |
|
| 83 |
def prep_for_rayst3r(img,depth_dict,mask):
|
| 84 |
H, W = img.shape[:2]
|