Nodes/Kongshan Nodes/检查空遮罩
ComfyUI Node

检查空遮罩

Tell Me if This Mask Found Anything — as a Number Your Logic Nodes Can Use

By kongshan4219·Created 3 months ago·Updated 3 months ago· 0
检查空遮罩
  • mask
  • boolean_number

KSIsMaskEmpty answers one question: is this mask completely empty? All pixels zero → it outputs 1. Anything at all → 0. And it emits that as a NUMBER, deliberately, because a plain 1/0 number is the easiest thing in the world to feed into a conditional node, an if switch, or a workflow gate.

Why you'd reach for it

In an automated pipeline, "did the detection find anything?" is a question you ask constantly, and the answer has to do something. The Kongshan segmentation chain hands you exactly the case: KSSAMSegmentByBoxes returns an empty black mask placeholder when a frame had no boxes (rather than erroring), KSGroundingDinoDetect gives you box_count but that's an INT on a different node. This node is the generic "is there a mask here at all" signal you can branch on.

The concrete pattern: GroundingDINO finds nothing (empty SAM mask → 1 here) → route to a fallback that loads a manual mask or skips the product; a real mask (0) → continue to background compositing. That's a workflow-level "empty results handling" decision, and this node is the cheap sensor that feeds it. It's also a debugging friend: drop it in, and 1 tells you your upstream detection is failing before you stare at a black image wondering what happened.

The inputs

One required input: mask, a standard ComfyUI MASK. Output is a single boolean_number of type NUMBER - 1 when the mask is entirely zeros, 0 otherwise. The NUMBER (rather than INT or a native boolean) choice is deliberate: it plugs into float-tolerant conditionals without type friction. ComfyUI's newer core has native boolean primitives now, but NUMBER still plays nicer with third-party logic packs, and this node's author clearly optimized for "just wire it into whatever."

Installing

With the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/kongshan4219/ComfyUI-Kongshan-Nodes

restart ComfyUI. Trivial - no models, no keys, torch only.

Gotchas

  • "Empty" means all pixels zero. A mask with one stray dot is not empty, so a noisy SAM mask will happily report 0. If your gate keeps surprising you, check for specks upstream (min_mask_component_area on the pack's background nodes kills them).
  • It's all-or-nothing. There's no "mostly empty" here, no area threshold, no percentage. If you need "product occupies less than X% of the frame," this node can't tell you - you'd want an area-computing node.

This is a genuinely thin utility - 300 words of value in a pack of heavier hitters. But the design choice (boolean as a NUMBER, built for gating) is the kind of small thing that separates a pack an author actually runs from one they merely shipped. That's this whole pack in miniature.

CategoryKongshan/Local

Inputs (1)

NameTypeDefaultDescription
maskMASK待检查遮罩。所有像素都为 0 时视为空遮罩。

Outputs (1)

NameTypeDescription
boolean_numberNUMBER