IsMaskEmptyNode (template matching)
The 'did the previous node find anything?' signal your workflow has been missing
- mask
- boolean_number
This is a two-line node, and it's genuinely useful. It takes a MASK in, and returns a single NUMBER: 1 when the mask is entirely black, 0 when there's any white pixel in it. The whole implementation is torch.all(mask == 0).int().item() - literally "is every pixel zero?"
Why you'd reach for it
It answers the question ComfyUI never asks for you: did the previous step actually find anything? Its packmate, TemplateMatching (template matching), returns an all-black mask whenever it finds no match - which your downstream inpaint, crop, or regenerate nodes will cheerfully consume and turn into garbage at full generation cost. Route that mask through IsMaskEmptyNode first and you can skip the entire rest of the pipeline when there's nothing to work on.
That empty-result handling is the difference between a brittle automation and one that survives the real world. Batch jobs run unattended; the first image without a logo match shouldn't produce an inpainted smudge. This node turns "maybe empty" into a branch you can actually take.
How it wires in
- Input:
mask(MASK) - the output of a detection or template-matching node. - Output:
boolean_number(NUMBER) -1means empty,0means not.
Note the type: it's a NUMBER, not a ComfyUI BOOLEAN, but it's always exactly 0 or 1, so any conditional/branch node that accepts a numeric flag treats it as a boolean - 1 = true = "the mask is empty". The common pattern is: if empty, feed a fallback path; if not empty, crop or inpaint the matched region. Pair it with the pack's own TemplateMatching node and you've got a complete "search for a logo, and only edit it when it exists" workflow.
One honest caveat: it only checks whether any pixel is nonzero, so a mask with a single stray white pixel counts as "not empty." If your detector is noisy, you may want to clean up the mask before asking this question - or just accept the occasional wasted pass on a near-empty mask, which is usually the cheaper option anyway.
Installing it
Same pack as the main node, so the install story is identical - ComfyUI Manager, search "ComfyUI template matching", install and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/wentao-uw/ComfyUI-template-matching
It has no extra dependencies of its own beyond what the pack needs (opencv-python, numpy, matplotlib, torch - the heavy two already ship with ComfyUI). It's the quiet little signal node you didn't know you needed, and it does exactly one job correctly.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| boolean_number | NUMBER | — |