Split trimap and dropout-fill segmentation backends

Add SegmentationSettings.fill_backend / fill_model_name so the dropout-fill can
use a different (higher-recall) segmenter than the trimap. Default is now the
combination the investigation converged on: BiRefNet builds the trimap (reliable
topology -- finger gap removed, strands kept as sure_fg), anime-seg drives the
fill (more, more-coherent anime wisps). Because the fill only adds (max), a
higher-recall-but-less-reliable mask there is harmless.

On TestImage2 this eliminates the strand breakage a full anime-seg pipeline
caused (lost 699 -> 0) while keeping ~91% of its extra wisp recall (gained
1133 -> 1031). Strands stay continuous; the recovered wisps are anime-seg's
coherent curves rather than BiRefNet's grainy fill.

Also adds an optional unsharp-mask knob (segmentation.sharpen, default off).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 11:17:46 +08:00
parent 08378e57f8
commit 9805b51b99
4 changed files with 45 additions and 2 deletions
+4
View File
@@ -106,8 +106,12 @@ class SegmentationSettings:
enabled: bool = True
backend: str = "birefnet" # "birefnet" or "anime-seg"
model_name: str = "ZhengPeng7/BiRefNet"
fill_backend: str = "" # "" = reuse `backend` for dropout-fill; else e.g. "anime-seg"
fill_model_name: str = ""
device: str = "cuda"
input_size: int = 1024
sharpen: float = 0.0 # unsharp-mask amount on the mask (0 = off)
sharpen_radius: int = 4
@dataclass(frozen=True)