Simplify to single-segmenter pipelines; add screen_color prior; drop rescue + recolor

Strategic pivot: the dropout-fill rescue, the anime-seg fill backend, the
BiRefNet+anime-seg intersection, and the recolor pass all existed to repair
source images whose hair was already green-contaminated or broken at generation
time. Fixing the source instead (clean pastel-background generation) makes the
matte high-contrast, so that whole compensation layer is unnecessary. Remove it.

- Two pipelines via segmentation.enabled:
    false -> chroma-only (Chroma + ViTMatte)
    true  -> single segmenter (default anime-seg, switchable birefnet) -> trimap
  then ViTMatte refines, pymatting estimates foreground, despill cleans spill.

- Generalise the green-hardcoded colour logic to a screen_color prior (hex, e.g.
  "#CFEFFF"; default null = green auto-detect, byte-identical). chroma keys off
  Lab/RGB distance to the colour; despill removes chroma along its Lab direction.
  Added --screen-color CLI flag.

- Removed dead code: fill_seg_dropouts + seg_fill*/intersection params,
  SegmentationSettings.fill_backend/fill_model_name/sharpen, unsharp_mask,
  recolor.py + RecolorSettings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 15:33:58 +08:00
parent 87359ca304
commit 7555321cfc
10 changed files with 142 additions and 245 deletions
+10 -20
View File
@@ -1,3 +1,8 @@
# Background-colour prior. null = auto-detect a green screen (default behaviour).
# A hex string like "#CFEFFF" keys chroma + despill off that colour instead, for
# arbitrary (e.g. pastel) flat backgrounds. Also overridable via --screen-color.
screen_color: null
model:
model_name: hustvl/vitmatte-base-composition-1k
device: cuda
@@ -5,11 +10,11 @@ model:
fallback_to_chroma_alpha: false
segmentation:
# enabled: true = single-segmenter pipeline (one seg model drives the trimap)
# enabled: false = no seg model, chroma-only pipeline (Chroma + ViTMatte)
enabled: true
backend: birefnet # birefnet | anime-seg (anime-seg needs model_name: skytnt/anime-seg)
model_name: ZhengPeng7/BiRefNet
fill_backend: anime-seg # dropout-fill uses anime-seg (higher wisp recall; add-only, harmless)
fill_model_name: skytnt/anime-seg
backend: anime-seg # single trimap segmenter; switchable: anime-seg | birefnet
model_name: skytnt/anime-seg # birefnet -> ZhengPeng7/BiRefNet
device: cuda
input_size: 1024
@@ -26,11 +31,6 @@ alpha_post:
chroma_suppress_bg_low: 0.35
chroma_suppress_bg_high: 0.80
chroma_suppress_strength: 1.0
seg_fill: true
seg_fill_alpha_max: 0.10
seg_fill_seg_min: 0.10
seg_fill_strength: 0.70
seg_fill_min_area_ratio: 0.00002
foreground:
enabled: true
@@ -56,14 +56,4 @@ despill:
green_excess_margin: 0.015
edge_expand_radius: 2
alpha_weight_floor: 0.35
recolor:
enabled: true
person_threshold: 0.5
coverage_soft: 0.08
contam_low: 0.02
contam_high: 0.12
clean_dom_max: 0.03
propagate_radius_ratio: 0.02
min_reference_weight: 0.05
luminance_strength: 0.5
color_margin_lab: 4.0 # custom-screen despill: Lab chroma margin (screen_color set)