fix: use modern matplotlib colormap API
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import uuid
|
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
-
|
| 17 |
import numpy as np
|
| 18 |
import torch
|
| 19 |
import trimesh
|
|
@@ -113,7 +113,7 @@ def clear_depth_pipeline():
|
|
| 113 |
|
| 114 |
def make_depth_preview(depth: np.ndarray) -> Image.Image:
|
| 115 |
depth = (depth - depth.min()) / max(float(depth.max() - depth.min()), 1e-6)
|
| 116 |
-
rgb = (
|
| 117 |
return Image.fromarray(rgb)
|
| 118 |
|
| 119 |
|
|
@@ -121,13 +121,13 @@ def make_confidence_preview(confidence: np.ndarray) -> Image.Image:
|
|
| 121 |
confidence = np.asarray(confidence, dtype=np.float32)
|
| 122 |
confidence = np.nan_to_num(confidence, nan=0.0, posinf=1.0, neginf=0.0)
|
| 123 |
confidence = (confidence - confidence.min()) / max(float(confidence.max() - confidence.min()), 1e-6)
|
| 124 |
-
rgb = (
|
| 125 |
return Image.fromarray(rgb)
|
| 126 |
|
| 127 |
|
| 128 |
def make_uncertainty_preview(uncertainty: np.ndarray) -> Image.Image:
|
| 129 |
uncertainty = np.clip(np.nan_to_num(np.asarray(uncertainty, dtype=np.float32)), 0.0, 1.0)
|
| 130 |
-
rgb = (
|
| 131 |
return Image.fromarray(rgb)
|
| 132 |
|
| 133 |
|
|
|
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
+
from matplotlib import colormaps
|
| 17 |
import numpy as np
|
| 18 |
import torch
|
| 19 |
import trimesh
|
|
|
|
| 113 |
|
| 114 |
def make_depth_preview(depth: np.ndarray) -> Image.Image:
|
| 115 |
depth = (depth - depth.min()) / max(float(depth.max() - depth.min()), 1e-6)
|
| 116 |
+
rgb = (colormaps.get_cmap("magma")(1.0 - depth)[..., :3] * 255).astype(np.uint8)
|
| 117 |
return Image.fromarray(rgb)
|
| 118 |
|
| 119 |
|
|
|
|
| 121 |
confidence = np.asarray(confidence, dtype=np.float32)
|
| 122 |
confidence = np.nan_to_num(confidence, nan=0.0, posinf=1.0, neginf=0.0)
|
| 123 |
confidence = (confidence - confidence.min()) / max(float(confidence.max() - confidence.min()), 1e-6)
|
| 124 |
+
rgb = (colormaps.get_cmap("viridis")(confidence)[..., :3] * 255).astype(np.uint8)
|
| 125 |
return Image.fromarray(rgb)
|
| 126 |
|
| 127 |
|
| 128 |
def make_uncertainty_preview(uncertainty: np.ndarray) -> Image.Image:
|
| 129 |
uncertainty = np.clip(np.nan_to_num(np.asarray(uncertainty, dtype=np.float32)), 0.0, 1.0)
|
| 130 |
+
rgb = (colormaps.get_cmap("inferno")(uncertainty)[..., :3] * 255).astype(np.uint8)
|
| 131 |
return Image.fromarray(rgb)
|
| 132 |
|
| 133 |
|