Nodes/ComfyUI-DAELab-Custom-Nodes-Library/徽章选区 Mask (DAELab)
ComfyUI Node

徽章选区 Mask (DAELab)

Draw the region on the badge instead of guessing hex codes

By TeutonicMepheles·Created 4 months ago·Updated 3 days ago· 0
徽章选区 Mask (DAELab)
  • image
  • color
  • selection_preview
  • raw_mask
◄vertex_count4►
◄fill_opacity35►
◄outline_width3►
◄polygon_data►

Color matching gets you a long way on a badge: the enamel is one flat colour, the metal ring is another, and a mask-by-colour node picks them cleanly. Until it doesn't - a highlight, a gradient in the render, two regions that came out suspiciously similar, or a detail that isn't a colour region at all. At that point you want to draw.

徽章选区 Mask (DAELab) is the manual escape hatch. It's an interactive polygon-and-brush editor that takes an image, lets you draw closed polygons and round brush strokes over it inside the node, and gives you a clean binary mask at the input image's own size.

How it works

It's a subclass of the pack's Polygon Mask node with the badge-specific defaults baked in - that's why the input list looks like a vector editor rather than a node: vertex_count, color, fill_opacity, outline_width, plus polygon_data.

polygon_data is the hidden part. The front end owns the actual state - vertices, selected polygon, undo history, brush strokes - as normalised coordinates, and writes it into that string widget right before the prompt is built. On the Python side the node rasterises every polygon into an all-zero mask, then draws the stored brush strokes on top as round-capped lines with a diameter that scales off min(width, height). The result is repeated across the batch so a mask lines up with every frame.

Two things follow from that design and both are worth internalising.

First, color, fill_opacity and outline_width are preview cosmetics. They change how the overlay looks in selection_preview so you can see what you picked. raw_mask comes out at full strength, white inside, black outside - which is exactly what a masked GPT edit or an inpaint node wants. Don't go hunting for a "mask strength" dial; there isn't one, because there shouldn't be.

Second, the mask is generated at the input image's resolution, not at some internal canvas size. If you're doing badge work, put this after the pack's canvas-normalising node so that "input resolution" is a predictable 1024 square. Otherwise your mask dimensions will quietly change when someone uploads a different photo.

Drawing in it

The editor inherits the pack's polygon interactions: Shift + left-click on empty canvas adds a triangle, Shift + right-click removes a polygon, clicking a fill selects it, dragging the fill moves it and dragging a vertex reshapes it - and you can add or delete vertices on the selected polygon as long as you keep at least three and no more than fifty. Reset rebuilds the selected polygon with the current vertex_count and keeps its centre.

Two behaviours that save you a lot of swearing:

  • Queue the prompt straight after dragging a vertex. The node's state-sync runs before the prompt is built, so the queued run uses the vertices you just left on screen, not the ones from the last time you pressed something.
  • Change the input image and your masks survive. Same aspect ratio keeps absolute coordinates; a different size scales every vertex proportionally. The exception is if you deliberately hit Clear - then the node respects that and keeps giving you an empty mask instead of helpfully re-adding a default triangle.

Outputs

raw_mask is the one you wire onward - into the semantic region GPT channel, into a composite node, into an inpaint. selection_preview is the same image with the polygons drawn over it at your fill_opacity; useful for eyeballing and for showing a client what's about to change, not useful as data.

Note there's no text passthrough on this variant, unlike the general Polygon Mask. If you were using that to ferry a prompt string through the canvas, add a separate text node.

Install

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

Restart ComfyUI and refresh the browser - the polygon editor is a web/ JavaScript module, so a stale tab gives you a node with a blank square where the canvas should be. In ComfyUI Manager, search for the pack title "ComfyUI-DAELab-Custom-Nodes-Library"; the node appears under DAELab/Badge.

Gotchas

It needs a real batched IMAGE input. Wiring a mask or a string into image throws "Badge selection requires a batched IMAGE" rather than doing something clever.

The node isn't an output node, so you have to queue the workflow to get raw_mask out - drawing alone updates the preview, not the tensor. If you want the mask without a full run, that's a different node in the pack (Polygon Mask, with its preview/apply flow); this variant expects to sit in front of a generate step.

Finally, don't stack this node with an aggressive colour mask "just in case". Union of a dragged polygon and a colour match gives you a mask with a wandering boundary that's hard to reason about when a paid edit comes back wrong. Pick one source of truth per region, and reach for the polygon when colour matching has visibly failed.

CategoryDAELab/Badge

Inputs (6)

NameTypeDefaultDescription
imageIMAGE—
vertex_countINT43–50—
colorCOLOR#FF1744—
fill_opacityINT350–100—
outline_widthINT30–20—
polygon_dataSTRING—

Outputs (2)

NameTypeDescription
selection_previewIMAGE—
raw_maskMASK—