ComfyUI Node Runs on cloud

IsMaskEmpty

IsMaskEmpty

By storyicon·Created 3 years ago·Updated 2 years ago· 1,114
IsMaskEmpty
  • mask
  • boolean_number

Did the segmenter actually find anything? This node answers that, in one number. Feed it a mask and it tells you whether the mask is blank - all black, nothing selected - or not. It's a tiny logic node, the kind of thing you never think about until you're running a batch and need your graph to know when a detection came up empty.

Why you'd reach for it

Text-prompted masking isn't guaranteed to hit. Run GroundingDinoSAMSegment with the prompt "sunglasses" across a folder of portraits and plenty of those people won't be wearing any - GroundingDINO finds nothing, SAM has no box to trace, and you get an empty mask. If the rest of your workflow blindly tries to inpaint that empty mask, at best it wastes a sampling pass and at worst it does something weird to the whole frame.

IsMaskEmpty is the check that lets a pipeline branch on "was anything detected." It's what turns a one-shot masking node into something you can trust in an automated, unattended run - the batch use case that made GroundingDINO+SAM popular in the first place. You segment, you ask "is it empty," and you route accordingly: skip, fall back, or carry on.

How it works

A ComfyUI mask is a grayscale array where each pixel is a selection strength from 0.0 to 1.0. "Empty" means every pixel is 0 - nothing is selected anywhere. This node scans the mask and returns a boolean-style flag: one value if the mask is blank, the other if it contains any selected pixels at all. It's a reduction over the whole array, so it's cheap and instant - no model, no GPU.

The inputs and outputs that matter

One input: mask (MASK), the mask you want to test.

One output: boolean_number, typed as NUMBER. It's a plain numeric flag - think 1 for "yes, empty" and 0 for "no, there's something here" - that you feed into whatever consumes a boolean or a number downstream: a switch, a conditional, a logic gate from another utility pack. The name is literal; treat the output as a true/false expressed as a number.

How to install it

It's bundled in the segment anything pack, so installing that gives you this node. ComfyUI Manager: search segment anything (the storyicon pack), install, restart. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/storyicon/comfyui_segment_anything

then pip install -r requirements.txt and restart. Like the other mask utilities in this pack, IsMaskEmpty needs no model download and no GPU - it's pure array logic. Even if the GroundingDINO half of the pack refused to compile on your machine, this node still loads and runs.

Common issues & troubleshooting

Check which way the flag points. The output is a number standing in for true/false, and the one thing that trips people is assuming the polarity without checking - does "empty" give you 1 or 0? Wire it to a debug/preview once and confirm before you build branching logic on top of it, so your "skip if empty" branch doesn't quietly become "skip if not empty."

"Empty" is exact, so nearly-empty still counts as non-empty. A single stray selected pixel - a tiny false-positive box from GroundingDINO, or a speck of soft mask edge - makes the mask technically non-empty. If you're using this to gate real work, that one pixel will read as "found something." When that matters, clean or threshold the mask upstream before testing it, rather than expecting this node to ignore trivial detections; it reports what's there, it doesn't judge whether it's enough.

That's the node. It does one small thing and does it reliably - the value is entirely in what you wire it into.

Categorysegment_anything

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
boolean_numberNUMBER