Add directional trimap mode (default); keep seg/hard-bg via trimap.mode

Replace the two experimental bools (directional, bg_hued_to_bg) with a single
TrimapSettings.mode selector for the segmentation pipeline:
  - "directional" (new default): chroma magnitude + seg + a Lab hue-direction
    split. In the chroma-unknown zone a confidently-segmented pixel stays
    foreground unless it is displaced toward the background hue, so a neutral
    background-coloured garment (e.g. a white shirt) is kept while a background-
    hued residual (blue between hair strands) is left unknown for ViTMatte /
    chroma-suppress to clear.
  - "seg": original fuse_trimap, unchanged.
  - "directional-hard-bg": aggressive variant that hard-removes background-hued
    pixels (can eat cool/shadowed white cloth).

Selectable via configs/default.yaml (trimap.mode) or CLI --trimap-mode; unknown
modes raise. Default CLI output verified byte-identical to the reviewed UNK
result on the pastel sample.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 19:27:09 +08:00
parent 22ef1d6336
commit 5f48f7a2cd
6 changed files with 122 additions and 2 deletions
+13
View File
@@ -28,6 +28,19 @@ class TrimapSettings:
# Semantic fusion thresholds (used by fuse_trimap when segmentation is on).
seg_core_threshold: float = 0.60
seg_loose_threshold: float = 0.08
# Trimap mode for the segmentation pipeline (the chroma-only pipeline ignores it):
# "directional" (default) -- chroma magnitude + seg + a hue-direction split. In
# the chroma-unknown zone a confidently-segmented pixel stays foreground
# unless it is displaced toward the background hue: a neutral background-
# coloured garment (e.g. a white shirt) is kept, while a background-hued
# residual (e.g. blue trapped between hair strands) is left UNKNOWN for
# ViTMatte / chroma-suppress to clear.
# "seg" -- original fuse_trimap: seg topology + chroma veto, no hue split.
# "directional-hard-bg" -- like "directional" but hard-marks background-hued
# pixels as background; more aggressive, can eat cool/shadowed white cloth.
mode: str = "directional"
seg_low: float = 0.15 # seg below this -> background-eligible; at/above -> foreground-eligible
bg_hue_proj_min: float = 4.0 # Lab a*/b* projection onto bg direction above which a pixel is background-hued
@dataclass(frozen=True)