Add cross-model veto of hair-gap background residue (default on)
Colour-drifted background trapped between hair strands defeats every single-signal defence: the chroma key reads it as foreground (bgc ~0.07), the segmenter backs it, ViTMatte rates it opaque, and post-hoc removal is a proven dead end (it shreds the hair volume the same pixels belong to). A second, trimap-free matting model (BiRefNet_HR-matting) is the only tested model that separates this residue from the subject, so its opinion is fused in as a veto: min-fusion that may only LOWER alpha, restricted to the background-hued bright suspect zone (proj >= 3, L >= 45, feathered) and gated by primary-alpha confidence (0.70 -> 0.95 ramp) so soft wisps and dark hair are exempt by construction. - settings/config/CLI: cross_check block, --cross-check/--no-cross-check - alpha_post.cross_check_alpha after clean_alpha; second opinion reuses BiRefNetSegmenter; saved to debug as cross_check_alpha.png - chroma.bg_hue_projection extracted and shared with the trimap - docs: methodology.md (new), hair_gap_artifacts.md (investigation log) Verified: cross-check ON reproduces the visually-reviewed B1gate prototype byte-for-byte on TestImage3; --no-cross-check reproduces the previous baseline byte-for-byte; pink-bg FixImage1 face untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+3
-8
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
|
||||
from .chroma import bg_hue_projection
|
||||
from .deps import require_cv2
|
||||
from .settings import TrimapSettings
|
||||
|
||||
@@ -137,14 +138,8 @@ def fuse_trimap_directional(
|
||||
chroma_unknown = ~chroma_bg & ~chroma_fg
|
||||
core = seg_mask >= settings.seg_core_threshold
|
||||
|
||||
# Directional chroma: projection of (a*, b*) onto the background chroma
|
||||
# direction. Positive = colour displaced toward the background hue.
|
||||
lab_c = np.asarray(lab_center, dtype=np.float32)
|
||||
mag = float(np.hypot(lab_c[1], lab_c[2]))
|
||||
if mag < 1e-3:
|
||||
proj = np.zeros(shape, dtype=np.float32)
|
||||
else:
|
||||
proj = (lab[..., 1] * lab_c[1] + lab[..., 2] * lab_c[2]) / mag
|
||||
# Directional chroma: positive = colour displaced toward the background hue.
|
||||
proj = bg_hue_projection(lab, lab_center)
|
||||
bg_hued = proj >= settings.bg_hue_proj_min
|
||||
|
||||
bg = chroma_bg | ((seg_mask < settings.seg_low) & ~chroma_fg)
|
||||
|
||||
Reference in New Issue
Block a user