Spaces:
Runtime error
Runtime error
Rawal Khirodkar commited on
Commit ·
9a37519
1
Parent(s): c7182c9
Pointmap: kill mesh holes — morphological CLOSE on fg mask + loosen max_edge to 4cm
Browse files
app.py
CHANGED
|
@@ -142,7 +142,12 @@ def _foreground_mask(image_pil: Image.Image, target_h: int, target_w: int) -> np
|
|
| 142 |
with torch.no_grad():
|
| 143 |
out = fg(inputs)
|
| 144 |
out = F.interpolate(out, size=(target_h, target_w), mode="bilinear", align_corners=False)
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
def _depth_to_rgb(depth: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
|
@@ -183,7 +188,7 @@ def _camera_marker(radius: float = 0.025, n_points: int = 600,
|
|
| 183 |
|
| 184 |
|
| 185 |
def _triangulate_grid(pointmap_hwc: np.ndarray, mask_hw: np.ndarray,
|
| 186 |
-
max_edge: float = 0.
|
| 187 |
"""Build a triangulated mesh from the (H, W) pointmap grid.
|
| 188 |
|
| 189 |
Returns (verts, uvs, faces). Each valid pixel becomes a vertex; adjacent
|
|
@@ -221,7 +226,7 @@ def _triangulate_grid(pointmap_hwc: np.ndarray, mask_hw: np.ndarray,
|
|
| 221 |
|
| 222 |
|
| 223 |
def _make_glb(image_pil_native: Image.Image, pointmap_hwc: np.ndarray,
|
| 224 |
-
mask_hw: np.ndarray, max_edge: float = 0.
|
| 225 |
h, w = pointmap_hwc.shape[:2]
|
| 226 |
image_native = image_pil_native.resize((w, h), Image.LANCZOS)
|
| 227 |
|
|
|
|
| 142 |
with torch.no_grad():
|
| 143 |
out = fg(inputs)
|
| 144 |
out = F.interpolate(out, size=(target_h, target_w), mode="bilinear", align_corners=False)
|
| 145 |
+
mask = (out.argmax(dim=1)[0] > 0).cpu().numpy().astype(np.uint8)
|
| 146 |
+
# Morphological closing fills small false-negative holes inside the figure
|
| 147 |
+
# (shadows, dark hair, between fingers) so the mesh doesn't show pinpricks.
|
| 148 |
+
kernel = np.ones((5, 5), np.uint8)
|
| 149 |
+
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
|
| 150 |
+
return mask.astype(bool)
|
| 151 |
|
| 152 |
|
| 153 |
def _depth_to_rgb(depth: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
def _triangulate_grid(pointmap_hwc: np.ndarray, mask_hw: np.ndarray,
|
| 191 |
+
max_edge: float = 0.04):
|
| 192 |
"""Build a triangulated mesh from the (H, W) pointmap grid.
|
| 193 |
|
| 194 |
Returns (verts, uvs, faces). Each valid pixel becomes a vertex; adjacent
|
|
|
|
| 226 |
|
| 227 |
|
| 228 |
def _make_glb(image_pil_native: Image.Image, pointmap_hwc: np.ndarray,
|
| 229 |
+
mask_hw: np.ndarray, max_edge: float = 0.04) -> str:
|
| 230 |
h, w = pointmap_hwc.shape[:2]
|
| 231 |
image_native = image_pil_native.resize((w, h), Image.LANCZOS)
|
| 232 |
|