Add recolor pass to clean residual contamination colour
Add bgfilter/recolor.py: after despill, propagate clean neighbour chroma into pixels whose colour is still off (residual green, or the magenta a green unmix overshoots into), keeping luminance partway so hair texture survives. It installs a real observed colour rather than subtracting, so it cannot overshoot. Despill already neutralises the matte edge (off ~ 0 there), so recolor only touches the contaminated interior and the wisps the dropout-fill rescued. Runs as a final colour pass on the despilled foreground; pymatting + despill keep their stronger edge handling. On the samples the magenta fringe drops sharply (TestImage vis-magenta 0.065->0.014, TestImage2 0.085->0.031) with edge green unchanged (vis-green ~0.02). Debug output color_mask.png replaces the despill / foreground-background / foreground-correction maps; smoke updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from .alpha_post import (
|
||||
from .chroma import compute_bg_confidence
|
||||
from .despill import despill_green
|
||||
from .foreground import estimate_foreground_rgb
|
||||
from .recolor import recolor_foreground
|
||||
from .io import load_rgb, save_gray, save_rgb, save_rgba, write_text
|
||||
from .qa import BACKGROUND_COLORS, composite, make_qa_grid, save_previews
|
||||
from .settings import PipelineSettings
|
||||
@@ -96,9 +97,12 @@ def _run_image(
|
||||
foreground = estimate_foreground_rgb(
|
||||
rgb, alpha, bg_confidence, model, settings.foreground
|
||||
)
|
||||
corrected_rgb, despill_mask = despill_green(
|
||||
corrected_rgb, color_mask = despill_green(
|
||||
foreground.rgb, alpha, model, settings.despill
|
||||
)
|
||||
if settings.recolor.enabled:
|
||||
recolored = recolor_foreground(corrected_rgb, alpha, seg_mask, settings.recolor)
|
||||
corrected_rgb, color_mask = recolored.rgb, recolored.mask
|
||||
save_rgba(output_path, corrected_rgb, alpha)
|
||||
|
||||
result = {
|
||||
@@ -118,10 +122,8 @@ def _run_image(
|
||||
if seg_mask is not None:
|
||||
save_gray(debug / "seg_mask.png", seg_mask)
|
||||
save_gray(debug / "alpha.png", alpha)
|
||||
save_rgb(debug / "foreground_rgb.png", foreground.rgb)
|
||||
save_rgb(debug / "foreground_background.png", foreground.background)
|
||||
save_gray(debug / "foreground_correction.png", foreground.correction)
|
||||
save_gray(debug / "despill_mask.png", despill_mask)
|
||||
save_rgb(debug / "foreground_rgb.png", corrected_rgb)
|
||||
save_gray(debug / "color_mask.png", color_mask)
|
||||
save_previews(debug, corrected_rgb, alpha)
|
||||
tiles = {
|
||||
"input": rgb,
|
||||
|
||||
Reference in New Issue
Block a user