Commit Graph

11 Commits

Author SHA1 Message Date
lhk229 d6cf6ffe0c Add chroma-guided alpha suppression for background holes
Pull alpha toward 0 in the unknown band where bg_confidence is high, so green
that survives in hair gaps and hole pockets goes transparent (doc section 10).
Runs between trimap enforcement and alpha cleanup; sure-foreground pixels are
never touched, keyed by the bg_confidence we already compute.

On the two samples this clears the faint outer green halo (edge pixels
19.3k -> 16.0k) but has little *visible* effect, because their residual is no
longer green: it is magenta from the pymatting unmix on genuine semi-transparent
hair (vis-magenta p95 ~0.07, identical pre/post despill), which this pass
deliberately leaves alone. The magenta needs a separate colour fix.

Knobs live in AlphaPostSettings (chroma_suppress*, default on).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 18:03:09 +08:00
lhk229 9b7a192599 Use pymatting ML foreground estimation to remove edge spill
After the full-foreground despill (5ddf0cd) the residual green was confined to
semi-transparent hair (alpha < 0.5): 85% of the worst pixels had alpha < 0.3,
where a pixel-wise unmix (divide by small alpha) is too noisy to trust.

Replace the hand-rolled unmix/local-blur estimator with pymatting's
estimate_foreground_ml (Germer et al. multi-level closed form), which propagates
reliable foreground colour from high-alpha neighbours into the fringe and
estimates the background, so green spill is unmixed rather than clamped. The
despill pass stays as a light cleanup on top.

- foreground.method selects "ml" (default) or "unmix" (legacy heuristic kept as
  a fallback when pymatting is unavailable, matching the chroma fallback idiom).
- ForegroundEstimate now exposes rgb (F), background (B) and a correction map;
  debug outputs become foreground_rgb / foreground_background / foreground_correction.

Controlled comparison (same ViTMatte alpha, only foreground method changed),
edge_green_excess:
  TestImage  p95 0.176->0.031, mean 0.061->0.005
  TestImage2 p95 0.165->0.004, mean 0.052->0.002

Adds pymatting (pulls in numba) to requirements.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 17:33:35 +08:00
lhk229 5ddf0cd392 Despill across full foreground to cut edge green spill
Green spill bleeds into pixels ViTMatte marks as solid foreground (alpha~1),
but despill was gated to the soft edge band (0.005<alpha<0.995) and weakened
exactly there: the alpha tent peaked at 0.5 and bg_confidence (low on the
character edge) further suppressed the correction.

- (1) Apply despill to the whole foreground (alpha > edge_low) instead of the
  soft band only; neutral pixels stay untouched via the green-excess term.
- (2) Weight by alpha at full strength across the opaque range (alpha>=0.5),
  easing off only where mostly transparent, instead of a tent peaking at 0.5.
- (3) Drop bg_confidence as a despill gate; localise purely by green excess.

Controlled comparison (same alpha, only despill changed), edge_green_excess:
  ViTMatte TestImage  p95 0.239->0.176, mean 0.131->0.061
  ViTMatte TestImage2 p95 0.231->0.165, mean 0.115->0.052

Removes now-unused DespillSettings fields edge_high and bg_confidence_weight.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 16:58:32 +08:00
Codex d6bb658244 Add foreground color estimation pass 2026-06-30 16:25:56 +08:00
Codex 1a670088c0 Use ViTMatte base composition model 2026-06-30 15:36:07 +08:00
Codex 10705d49df Support YAML pipeline configuration 2026-06-30 15:03:15 +08:00
Codex 923dbe9f09 Add sample smoke check and refine foreground despill 2026-06-30 14:42:08 +08:00
Codex 464a60c733 Improve despill and add quality checks 2026-06-30 14:29:19 +08:00
Codex 8fc53925e0 Implement green screen matting pipeline 2026-06-30 14:14:15 +08:00
Codex 4d2a2015fe Ignore sample and output directories 2026-06-30 13:43:37 +08:00
Codex bb61d2d3b6 Add green screen matting workflow 2026-06-30 13:39:24 +08:00