Spaces:
Running
Running
Keep background-coloured paint deep inside the silhouette (no more cut-out islands)
Browse files- projtex/validate.py +4 -1
projtex/validate.py
CHANGED
|
@@ -41,7 +41,10 @@ def foreground_mask(img: np.ndarray, depth: np.ndarray, thresh: float = 0.07) ->
|
|
| 41 |
diff = np.abs(cv2.GaussianBlur(img, (0, 0), 1.0) - bgc[None, None]).max(-1)
|
| 42 |
fg_g = diff > thresh
|
| 43 |
fg_g = cv2.morphologyEx(fg_g.astype(np.uint8), cv2.MORPH_OPEN, np.ones((3, 3), np.uint8)) > 0
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def silhouette_iou(img: np.ndarray, depth: np.ndarray) -> float | None:
|
|
|
|
| 41 |
diff = np.abs(cv2.GaussianBlur(img, (0, 0), 1.0) - bgc[None, None]).max(-1)
|
| 42 |
fg_g = diff > thresh
|
| 43 |
fg_g = cv2.morphologyEx(fg_g.astype(np.uint8), cv2.MORPH_OPEN, np.ones((3, 3), np.uint8)) > 0
|
| 44 |
+
# a re-framed output leaves background near the silhouette's edge; deep inside it, background-like colours are
|
| 45 |
+
# paint (misty blue-grey mountains on a mug were cut out, and another view's mountains showed through)
|
| 46 |
+
depth_in = cv2.distanceTransform(fg_r.astype(np.uint8), cv2.DIST_L2, 5)
|
| 47 |
+
return _fill_holes(fg_g) | (depth_in > 0.025 * max(img.shape[:2]))
|
| 48 |
|
| 49 |
|
| 50 |
def silhouette_iou(img: np.ndarray, depth: np.ndarray) -> float | None:
|