Auto-detect the background colour (default); drop the green heuristic
Replace the hardcoded green-screen auto-detection with a general flat-colour detector. When screen_color is null the background colour is now detected from the image border (dominant colour of the border strip) and used directly as the chroma model, with a failure gate that raises when the border is not one clean flat colour (gradient / texture / subject filling the frame). - chroma: add detect_background_color + _background_border_cluster; the null case of estimate_background_model samples the detected cluster directly (no seed search); compute_bg_confidence is now always perceptual (Lab/RGB distance). Removed the green heuristic (initial_green_candidates), the green multiplicative gating, the now-unused _smoothstep, and five green-only ChromaSettings fields. - pipeline: reuse the detected colour for de-spill in the auto case. - settings / default.yaml: add detect_* tuning fields; refresh screen_color docs. - README: document auto-detection + the failure gate, trimap modes, birefnet config. A supplied --screen-color hex still uses the seed-search refinement. Validated: detects green / pastel / text samples correctly, raises on gradient / two-colour, CLI exits 1 on failure, green and pastel mattes unchanged in quality. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,9 @@ def _run_image(
|
||||
bg_confidence, model = compute_bg_confidence(
|
||||
rgb, settings=settings.chroma, screen_color=screen_color
|
||||
)
|
||||
# With no colour given, chroma auto-detected one (model.rgb_center); reuse it for
|
||||
# despill so both key off the same background colour instead of the green path.
|
||||
despill_color = screen_color if screen_color is not None else tuple(model.rgb_center)
|
||||
if settings.segmentation.enabled:
|
||||
seg_mask = pipeline._segment(rgb)
|
||||
mode = settings.trimap.mode
|
||||
@@ -112,7 +115,7 @@ def _run_image(
|
||||
rgb, alpha, bg_confidence, model, settings.foreground
|
||||
)
|
||||
corrected_rgb, color_mask = despill_green(
|
||||
foreground.rgb, alpha, model, settings.despill, screen_color=screen_color
|
||||
foreground.rgb, alpha, model, settings.despill, screen_color=despill_color
|
||||
)
|
||||
save_rgba(output_path, corrected_rgb, alpha)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user