Spaces:
Running
Running
Widen the boundary gate and tighten thresholds — the rim ran 2px deep
Browse files- spritekit.py +6 -4
spritekit.py
CHANGED
|
@@ -185,8 +185,8 @@ def suppress_residual(
|
|
| 185 |
rgb: np.ndarray,
|
| 186 |
alpha: np.ndarray,
|
| 187 |
key_rgb: np.ndarray,
|
| 188 |
-
low: float = 0.
|
| 189 |
-
high: float = 0.
|
| 190 |
) -> np.ndarray:
|
| 191 |
"""Drive alpha to zero wherever the *final* color is still the backdrop.
|
| 192 |
|
|
@@ -214,8 +214,10 @@ def suppress_residual(
|
|
| 214 |
return alpha
|
| 215 |
direction = key_chroma / magnitude
|
| 216 |
fraction = np.einsum("...c,c->...", to_ycc(rgb)[..., 1:], direction) / magnitude
|
| 217 |
-
# High where transparency is nearby, ~0 anywhere inside the character.
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
return (alpha * (1.0 - boundary * _smoothstep(low, high, fraction))).astype(np.float32)
|
| 220 |
|
| 221 |
|
|
|
|
| 185 |
rgb: np.ndarray,
|
| 186 |
alpha: np.ndarray,
|
| 187 |
key_rgb: np.ndarray,
|
| 188 |
+
low: float = 0.25,
|
| 189 |
+
high: float = 0.45,
|
| 190 |
) -> np.ndarray:
|
| 191 |
"""Drive alpha to zero wherever the *final* color is still the backdrop.
|
| 192 |
|
|
|
|
| 214 |
return alpha
|
| 215 |
direction = key_chroma / magnitude
|
| 216 |
fraction = np.einsum("...c,c->...", to_ycc(rgb)[..., 1:], direction) / magnitude
|
| 217 |
+
# High where transparency is nearby, ~0 anywhere inside the character. The radius has to reach several pixels
|
| 218 |
+
# inward: measured across a real edge, the rim ran two pixels deep at alpha 0.85 and 0.99, and a tighter gate
|
| 219 |
+
# had already decayed to 0.16 by the second one and left it standing.
|
| 220 |
+
boundary = _smoothstep(0.05, 0.35, 1.0 - _box_blur(alpha[..., None], 6)[..., 0])
|
| 221 |
return (alpha * (1.0 - boundary * _smoothstep(low, high, fraction))).astype(np.float32)
|
| 222 |
|
| 223 |
|