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:
@@ -111,19 +111,6 @@ class AnimeSegSegmenter:
|
||||
return np.asarray(mask_img, dtype=np.float32) / 255.0
|
||||
|
||||
|
||||
def unsharp_mask(mask: np.ndarray, amount: float, radius: int) -> np.ndarray:
|
||||
"""Sharpen a soft mask: raise thin-strand peaks and crisp the blur so strands
|
||||
reach the sure-foreground threshold instead of dissolving into the unknown band."""
|
||||
if amount <= 0:
|
||||
return mask
|
||||
from .deps import require_cv2
|
||||
|
||||
cv2 = require_cv2()
|
||||
k = max(1, radius) * 2 + 1
|
||||
blur = cv2.GaussianBlur(mask, (k, k), 0)
|
||||
return np.clip(mask + amount * (mask - blur), 0.0, 1.0).astype(np.float32)
|
||||
|
||||
|
||||
def make_segmenter(settings: SegmentationSettings):
|
||||
if settings.backend == "birefnet":
|
||||
return BiRefNetSegmenter(settings)
|
||||
|
||||
Reference in New Issue
Block a user