fix(demo): harden mask hole-filling for border-touching cases

This commit is contained in:
2026-03-02 16:45:20 +08:00
parent cbb3284c13
commit f6859cfa79
2 changed files with 52 additions and 0 deletions
+28
View File
@@ -95,6 +95,34 @@ class TestMaskToSilhouette:
np.testing.assert_array_equal(result1, result2)
np.testing.assert_array_equal(result2, result3)
def test_hole_inside_mask_is_filled(self) -> None:
h, w = 200, 160
mask = np.zeros((h, w), dtype=np.uint8)
mask[30:170, 40:120] = 255
mask[80:120, 70:90] = 0
bbox = (40, 30, 120, 170)
result = mask_to_silhouette(mask, bbox)
assert result is not None
result_arr = cast(NDArray[np.float32], result)
hole_patch = result_arr[26:38, 18:26]
assert float(np.mean(hole_patch)) > 0.8
def test_hole_fill_works_when_mask_touches_corner(self) -> None:
h, w = 220, 180
mask = np.zeros((h, w), dtype=np.uint8)
mask[0:180, 0:130] = 255
mask[70:120, 55:95] = 0
bbox = (0, 0, 130, 180)
result = mask_to_silhouette(mask, bbox)
assert result is not None
result_arr = cast(NDArray[np.float32], result)
hole_patch = result_arr[24:40, 16:28]
assert float(np.mean(hole_patch)) > 0.75
def test_tall_narrow_mask_valid_output(self) -> None:
"""Tall narrow mask should produce valid silhouette."""
h, w = 400, 50