Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -397,7 +397,10 @@ def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, r
|
|
| 397 |
# subject on black via the soft matte - no background generated, no H3 denoise
|
| 398 |
progress(0.6, desc="Removing the background ...")
|
| 399 |
alpha = (matte.astype(np.float32).mean(-1) / 255.0)[..., None]
|
| 400 |
-
cutout =
|
|
|
|
|
|
|
|
|
|
| 401 |
waveform, sample_rate = (read_audio(clip) if keep_audio else (None, None))
|
| 402 |
stamp = int(time.time() * 1000)
|
| 403 |
out_path = os.path.join(OUTPUT_DIR, f"removed-{stamp}.mp4")
|
|
|
|
| 397 |
# subject on black via the soft matte - no background generated, no H3 denoise
|
| 398 |
progress(0.6, desc="Removing the background ...")
|
| 399 |
alpha = (matte.astype(np.float32).mean(-1) / 255.0)[..., None]
|
| 400 |
+
cutout = green.astype(np.float32) * alpha
|
| 401 |
+
# green-screen despill: cap the green channel to max(R, B) so the matte's green edge spill is removed
|
| 402 |
+
cutout[..., 1] = np.minimum(cutout[..., 1], np.maximum(cutout[..., 0], cutout[..., 2]))
|
| 403 |
+
cutout = cutout.round().clip(0, 255).astype(np.uint8)
|
| 404 |
waveform, sample_rate = (read_audio(clip) if keep_audio else (None, None))
|
| 405 |
stamp = int(time.time() * 1000)
|
| 406 |
out_path = os.path.join(OUTPUT_DIR, f"removed-{stamp}.mp4")
|