Nodes/ComfyUI-DAELab-Custom-Nodes-Library/Badge Edit Mask Validator (DAELab)
ComfyUI Node

Badge Edit Mask Validator (DAELab)

The adult in the room before a paid API call

By TeutonicMepheles·Created 4 months ago·Updated 2 days ago· 0
Badge Edit Mask Validator (DAELab)
  • edit_mask_flat
  • design_foreground_mask
  • base_render
  • edit_mask
  • should_edit
  • coverage
  • bounding_box
  • validation_status
  • diagnostic
◄registration_iou1.00►
◄minimum_registration_iou0.970►
◄allow_full_maskfalse►
◄full_mask_threshold0.995►

What it is and why you'd reach for it

Masked edits fail in three boring ways, and all three cost money when the masked edit is a GPT-Image-2 call. You select nothing and burn a request on an unchanged image. You select the whole badge and get a full regeneration wearing a mask's clothing. Or your selection doesn't actually sit on the badge, because registration slipped two pixels and now you're repainting background.

Badge Edit Mask Validator is the gate that checks for all three before the graph reaches the paid node. It also does the one bit of mask algebra that makes everything downstream safe: it intersects your hand-made selection with design_foreground_mask, so the mask leaving this node can only ever cover badge pixels. Badge Deterministic Composite relies on that. So does Badge Height Patch, which asserts that nothing outside the mask changed.

How it works

Four gates, in order. First, both masks must be binary - the node measures the distance of each pixel to either 0 or 1 and raises edit_mask_flat must be binary if anything is in between. Second, registration_iou is compared against minimum_registration_iou (0.97 by default) and raises Registration validation failed; local editing is blocked if the upstream Badge Master Registration didn't align. Third, the selection is intersected with the design foreground. Fourth, the surviving area is measured as coverage relative to the foreground, not relative to the canvas - if it's zero you get EMPTY_MASK and should_edit = False with the master passed through; if it's above full_mask_threshold (0.995) you get a hard error unless you've ticked the expert allow_full_mask box.

The bounding box output is computed from actual surviving pixels, including which batch index they landed in, which is handy when you queue four variations and want to know which one produced the stray selection.

Inputs and outputs that matter

edit_mask_flat is your selection - from a mask node, a colour-match node, a paint node. design_foreground_mask comes straight off Badge Design Canvas. base_render is only used to draw the diagnostic overlay; it doesn't affect the decision. registration_iou wires from the registration node's contour_iou. The two thresholds you might actually tune are minimum_registration_iou (loosen to 0.95 if you're fighting a legitimately soft silhouette) and allow_full_mask (off, and stay off unless you're deliberately doing a whole-badge restyle).

Outputs: edit_mask is the clipped, validated mask - this is the one you wire on. should_edit is the boolean that decides whether a routing/switch node lets the request through. coverage, bounding_box and validation_status are JSON/string QA. diagnostic is the base render with the selection tinted red.

Honest caveat about should_edit: this node computes it, but nothing in the pack enforces it for you. There's no built-in conditional branch - you need a switch or a bypass controller on the wire. The DAELab frontend ships a Boolean Group Bypass Controller for exactly this style of routing, which is the least friction if you're already in the pack.

Install

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

Restart ComfyUI. Manager install by pack title also works. Two dependency notes: the badge modules import OpenCV, which isn't in the pack's requirements.txt - pip install opencv-python-headless if the node is missing from the right-click menu - and the strict nodes need a ComfyUI new enough to provide comfy_api.latest.

Common issues

  • Full-mask edit blocked. Your selection covers ≥99.5% of the badge. Either your colour threshold is too loose, or you genuinely meant a full restyle and need allow_full_mask.
  • Registration validation failed. This is the node doing its job: the generated badge drifted from the design, so a mask drawn in design coordinates no longer means what you think. Fix the registration stage rather than lowering the threshold - 0.97 exists because a two-pixel slip is a visibly misaligned edit.
  • edit mask, foreground mask, and base render must share the same canvas. A GPT-Image-2 call returned 1536×1024 and nothing normalized it. This node won't resize for you.
  • Binary check fires after a blur. Put all feathering after this node, never before. A 4px blurred mask is a legitimate look but not a legitimate input here.
CategoryDAELab/Badge

Inputs (7)

NameTypeDefaultDescription
edit_mask_flatMASK—
design_foreground_maskMASK—
base_renderIMAGE—
registration_iouFLOAT1.000–1—
minimum_registration_iouFLOAT0.9700–1—
allow_full_maskBOOLEANfalse—
full_mask_thresholdFLOAT0.9950.5–1—

Outputs (6)

NameTypeDescription
edit_maskMASK—
should_editBOOLEAN—
coverageFLOAT—
bounding_boxSTRING—
validation_statusSTRING—
diagnosticIMAGE—