Nodes/ComfyUI-DAELab-Custom-Nodes-Library/Badge Design Canvas (DAELab)
ComfyUI Node

Badge Design Canvas (DAELab)

The node that decides what actually counts as your badge

By TeutonicMepheles·Created 4 months ago·Updated 2 days ago· 0
Badge Design Canvas (DAELab)
  • images
  • alpha_mask
  • normalized_flat_image
  • design_foreground_mask
  • width
  • height
  • diagnostic
◄canvas_width1024►
◄canvas_height1024►
◄image_resampling▾►
◄foreground_source▾►
◄background_color#ffffff►
◄cutout_color#ff00ff►
◄color_tolerance8►

What it is and why you'd reach for it

Every image-edit pipeline eventually has to answer one question: what part of this picture is the object, and what part is background? In the DAELab badge workflow this node is where that gets decided, once, authoritatively. It takes whatever flat badge artwork you have - a PNG with alpha, a JPEG sitting on white, a color-ID drawing on magenta - and turns it into two things: a normalized square design image and a hard-edged foreground mask.

That mask is the spine of the whole pack. Badge Master Registration scores how well a generated badge lines up with it (contour IoU, boundary error in pixels). Badge Edit Mask Validator clips your brush/color selection against it. Badge Height Reference Align V1 refuses to run if the height map doesn't cover it. Badge Render Prompt Builder counts unmatched height pixels inside it and throws if too many. If the silhouette coming out of this node is wrong, non-binary, or scaled differently from what downstream nodes expect, every check after it is measuring the wrong thing. This is the "bit-identical outside the mask" logic that masked editing has always owned and whole-image edit models never give you - the mask is the contract.

How it works

It is a contain-fit, not a crop and not a stretch. The node computes scale = min(canvas_width / w, canvas_height / h), resizes the artwork by that one factor, and centers it on a canvas filled with background_color. Mask and image get different resampling: your image_resampling choice (bicubic or nearest) applies to RGB, while the mask is always resized nearest-neighbour so it stays 0/1 rather than turning into a grey smear. Bicubic overshoot is clamped back to [0,1] at the end, which is why high-contrast edges don't blow up.

Foreground is inferred one of two ways, and the foreground_source enum decides which. Wire something into alpha_mask and the node treats 1 - alpha > 0.5 as foreground. Feed it nothing (or choose Explicit colors) and it does colour distance instead: a pixel is foreground only if it's further than color_tolerance / 255 from both background_color and cutout_color. That double test is the useful part - it lets you keep a magenta color-code channel out of the silhouette without re-exporting your artwork.

A JSON diagnostic comes out the far end with source_size, canvas_size, content_box, scale, which source it used, and foreground coverage. Read it. Coverage near 1.0 means your tolerance ate the whole canvas; coverage near 0.01 means you matched your own artwork as background.

Inputs and outputs that matter

Most people set four fields: canvas_width / canvas_height (default 1024×1024 - the strict nodes in this pack hard-require that size), foreground_source, and color_tolerance. Leave background_color at #ffffff unless your artwork really isn't on white, and leave cutout_color at #ff00ff unless your code channel is a different colour.

Outputs: normalized_flat_image and design_foreground_mask feed basically everything downstream; width and height are conveniences for anywhere you need the canvas size as integers; diagnostic is the JSON report.

Install

Search the pack title in ComfyUI Manager, or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/TeutonicMepheles/ComfyUI-DAELab-Custom-Nodes-Library

Restart ComfyUI afterwards - the pack ships a web/ directory of frontend scripts that only load on restart. One thing the README doesn't say: the badge nodes import cv2, and OpenCV is not in the pack's requirements.txt (that file only lists python-docx, openpyxl, pdfplumber for the storyboard importer). If this node vanishes from the menu after install:

pip install opencv-python-headless

Common issues

  • The node vanishes on startup. You're almost certainly on the cv2 path above, or your ComfyUI is too old for comfy_api.latest (some strict nodes use the V3 authoring API). Update ComfyUI core rather than installing a random pip package called comfy_api.
  • alpha_mask and images must have identical spatial dimensions. The node only forgives a mismatched alpha mask if it's entirely zero. Resize your mask, or use Explicit colors.
  • Load Image alpha gives you an empty foreground. Your PNG has no alpha channel, or alpha is fully opaque. Switch to Auto and let the colour test do it.
  • Fragmented or holey masks on JPEG sources. Tolerance 8 is tight. Bump it to 20–30 for anything that's been through lossy compression.
CategoryDAELab/Badge

Inputs (9)

NameTypeDefaultDescription
imagesIMAGE—
canvas_widthINT1024256–4096—
canvas_heightINT1024256–4096—
image_resamplingCOMBO2 options: bicubic, nearest
foreground_sourceCOMBO3 options: Auto: alpha, else explicit colors, Load Image alpha, Explicit colors
background_colorSTRING#ffffff—
cutout_colorSTRING#ff00ff—
color_toleranceINT80–255—
alpha_maskoptMASK—

Outputs (5)

NameTypeDescription
normalized_flat_imageIMAGE—
design_foreground_maskMASK—
widthINT—
heightINT—
diagnosticSTRING—