ComfyUI Node
BD Mask Resolver
Priority-based mask separation. Given a silhouette plus overlapping category masks (skin, clothes, accessories) and the original image, produces clean mutually-exclusive masks via priority + HSV color voting + neighbor-aware gap-fill. Python port of the Mask Resolver GLSL shader.
BD Mask Resolver
- silhouette
- skin_mask
- clothes_mask
- original_image
- accessories_mask
- clean_skin
- clean_clothes
- clean_accessories
- residual
- debug_overlay
- status
◄silhouette_threshold0.40►
◄skin_threshold0.50►
◄clothes_threshold0.50►
◄accessories_threshold0.50►
◄skin_priority1.0►
◄clothes_priority2.0►
◄accessories_priority3.0►
◄edge_softness0.30►
◄claim_threshold0.15►
◄gap_fill_strength0.80►
◄gap_neighbor_radius8►
◄color_weight0.60►
◄skin_color_modeadaptive_lab►
◄adaptive_tolerance25►
◄adaptive_sample_threshold0.70►
◄adaptive_min_samples50►
◄overlap_modepriority►
◄output_debug_vizfalse►
Category🧠BrainDead/Segmentation
Inputs (23)
| Name | Type | Default | Description |
|---|---|---|---|
| silhouette | MASK | Full character outline mask (white = character body, black = background). Defines the universe of pixels to assign to a category. Anything outside silhouette becomes background in all outputs. | |
| skin_mask | MASK | Mask of pixels you believe are skin (e.g. from BD_SAM3MultiPrompt with positive skin prompts). Will be clamped to silhouette. | |
| clothes_mask | MASK | Mask of pixels you believe are clothing. Will be clamped to silhouette. | |
| original_image | IMAGE | Original character image. Sampled per-pixel for HSV-based skin-tone detection (see color_weight). Resized to silhouette resolution if mismatched. | |
| accessories_maskopt | MASK | Optional mask for hard accessories (gloves, boots, belts, weapons). Defaults to all-zero if not provided. Highest default priority — wins overlaps with skin/clothes. | |
| silhouette_thresholdopt | FLOAT | 0.400–1 | Noise floor on the silhouette mask. Pixels in silhouette ABOVE this value count as character body, below count as background. Higher = stricter silhouette interpretation. NOT include/exclude — it's a noise filter. |
| skin_thresholdopt | FLOAT | 0.500–1 | Noise floor on the skin_mask input. Pixels above count as 'skin candidate', below are zeroed. Higher = only confidently-detected skin counts. Lower = pick up faint partial detections (and noise). |
| clothes_thresholdopt | FLOAT | 0.500–1 | Noise floor on the clothes_mask input. Same semantics as skin_threshold. |
| accessories_thresholdopt | FLOAT | 0.500–1 | Noise floor on the accessories_mask input. Same semantics as skin_threshold. |
| skin_priorityopt | FLOAT | 1.00.1–10 | Priority weight for skin when multiple masks claim a pixel. Default ranking: accessories(3) > clothes(2) > skin(1) — meaning a pixel claimed by both clothes and skin goes to clothes. Raise skin_priority above 2.0 to flip it. |
| clothes_priorityopt | FLOAT | 2.00.1–10 | Priority weight for clothes. See skin_priority for the ranking convention. |
| accessories_priorityopt | FLOAT | 3.00.1–10 | Priority weight for accessories. See skin_priority for the ranking convention. |
| edge_softnessopt | FLOAT | 0.300–1 | Smoothstep width around each input threshold. 0 = hard binary thresholds (sharp edges), higher = anti-aliased gradient at mask boundaries. |
| claim_thresholdopt | FLOAT | 0.150–2 | A pixel is 'claimed' by the winning category only if the winning score exceeds this. Pixels with weak/uncertain scores below claim_threshold become residual and are eligible for gap_fill. Raise this (e.g. 0.5+) to make residual generous (more gaps to fill); lower it to make claim aggressive (almost no residual). Default 0.15 = mild claim. |
| gap_fill_strengthopt | FLOAT | 0.800–1 | How aggressively to assign residual pixels via neighbor voting. 0 = leave residual untouched, 1 = fully assign residual to the strongest neighbor category. Only has an effect when residual is non-empty (controlled by claim_threshold). |
| gap_neighbor_radiusopt | INT | 81–64 | Radius (in pixels) of the neighborhood used to vote on residual pixels. Higher = looks further to find dominant category. Default 8 covers small gaps; raise to 16-32 for character art at high res. |
| color_weightopt | FLOAT | 0.600–1 | How much skin-tone detection influences scoring. 0 = ignore image color, only use input masks + priorities. 1 = strong color influence (skin pixels boosted toward skin, non-skin pixels boosted toward clothes). |
| skin_color_modeopt | COMBO | adaptive_lab | How to detect skin-toned pixels in the original image: adaptive_lab — sample reference skin color from confident skin_mask pixels, compute LAB ΔE distance per pixel. Self-tunes per character (works on pale white through dark African through reddish Navajo skin). fixed_hsv — hard-coded HSV ranges from the original GLSL shader. Fails on very pale/dark skin. Fallback for when adaptive can't sample enough pixels. both — multiply the two likelihoods. Strictest mode. |
| adaptive_toleranceopt | FLOAT | 252–100 | LAB ΔE distance at which adaptive likelihood = 0.5. Smaller = stricter (only pixels very close to sampled skin tone count). Larger = more permissive. ΔE 2.3 = just-noticeable difference, 25 = clearly different but related (typical skin variation), 50+ = very loose. |
| adaptive_sample_thresholdopt | FLOAT | 0.700–1 | Only skin_mask pixels above this value are used as reference samples for adaptive mode. Higher = use only the most confident skin pixels (better reference, fewer samples). Lower = use more pixels including soft edges (more samples, may include non-skin). |
| adaptive_min_samplesopt | INT | 5010–10000 | Minimum number of confident skin pixels needed for adaptive mode to activate. If fewer, adaptive returns zeros and falls back to fixed_hsv (in 'both' mode) or off. |
| overlap_modeopt | COMBO | priority | priority = winner takes all (each pixel goes to exactly ONE category). soft_blend = distribute proportionally by score (each pixel split fractionally; outputs may sum to >100% in overlap zones). |
| output_debug_vizopt | BOOLEAN | false | If True, debug_overlay shows color-coded overlap map: green=skin, blue=clothes, red=access, yellow=skin+clothes, magenta=skin+access, cyan=clothes+access, white=triple, gray=residual gap. Tinted by skin-tone confidence. If False, debug_overlay just shows the residual mask as RGB grayscale. |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| clean_skin | MASK | — |
| clean_clothes | MASK | — |
| clean_accessories | MASK | — |
| residual | MASK | — |
| debug_overlay | IMAGE | — |
| status | STRING | — |