ComfyUI Node
BD Mask Flatten
Flatten an image (RGB or RGBA) plus optional alpha mask onto a plain background or another image. Output is always RGB (no alpha) so downstream nodes don't need to handle transparency. Standard alpha composite math: image × alpha + bg × (1 - alpha) — semi-transparent pixels become bg-blended, so removing the bg later via chroma key gives percentage-based recovery. Channel-routing modes pack the image's grayscale into a single RGB channel (useful for game-engine packed maps).
BD Mask Flatten
- image
- mask
- background_image
- image
- alpha_used
◄background_colorwhite►
◄background_color_hex#808080►
◄flatten_modealpha_composite►
◄mask_strength1.00►
◄invert_maskfalse►
◄mask_threshold0.00►
◄edge_pad_pixels0►
Category🧠BrainDead/Segmentation
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| maskopt | MASK | Optional alpha mask. OVERRIDES image's alpha channel if both present. If not provided AND image is RGBA, uses image's alpha. If not provided AND image is RGB, treats as fully opaque (alpha=1). | |
| background_imageopt | IMAGE | Optional image to composite ONTO instead of a solid color. When provided, background_color and background_color_hex are ignored. Resized to match the input image's dimensions. | |
| background_coloropt | COMBO | white | Solid color background. red/green/blue/magenta = chroma keys. checker = gray checkerboard for debug visualization. custom = use background_color_hex. |
| background_color_hexopt | STRING | #808080 | Hex color when background_color='custom'. Format: '#RRGGBB' or '#RGB'. Falls back to gray if invalid. |
| flatten_modeopt | COMBO | alpha_composite | How to flatten: alpha_composite — standard alpha blend image RGB onto background. grayscale — convert image to luminance, alpha-composite onto background. image_to_red — put image's grayscale into ONLY the red channel (green/blue stay as bg). Useful for packing multiple grayscale maps into one RGB image for game engines. image_to_green / image_to_blue — same but for those channels. |
| mask_strengthopt | FLOAT | 1.000–2 | Multiply alpha values before composite. >1 makes alpha stronger (less bg shows through), <1 weaker (more bg shows through). Clamped to [0, 1] after. |
| invert_maskopt | BOOLEAN | false | Invert the alpha before applying — flattens the OUTSIDE of the mask onto background instead of the inside. |
| mask_thresholdopt | FLOAT | 0.000–1 | If > 0, binarize the alpha at this threshold before composite. 0 = soft (continuous alpha), >0 = hard binary cutoff. Useful when you want sharp edges instead of partial transparency on the flatten. |
| edge_pad_pixelsopt | INT | 00–512 | Voronoi edge padding — extend foreground RGB outward into transparent areas by N pixels using nearest-foreground color. Standard game-engine 'alpha bleed' to prevent UV-edge halos when textures are sampled at silhouette boundaries. 0 = off (no padding). 16-32 = typical for game textures. Applied BEFORE flattening, so the flatten background only shows beyond the padded zone. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| alpha_used | MASK | — |