Nodes/ComfyUI-WJNodes/Mask Detection
ComfyUI Node

Mask Detection

Check if a mask is actually empty before you waste a sampling pass on it

By 807502278·Created 2 years ago·Updated 11 months ago· 20
Mask Detection
  • image
  • mask
  • Exist?
  • HardEdge
  • PureWhite
  • PureBlack
  • PureGray
  • PureColorValue
accuracy255
Exist_threshold3

Automated masking pipelines fail quietly a lot of the time. A SAM detector doesn't find anything and hands you a solid black mask. A matting model returns solid white because it thought the whole frame was foreground. Neither of those looks broken in a preview - a solid-color image just looks like a normal, boring image - until you feed it downstream and something behaves strangely three nodes later, with no obvious cause. This node exists to catch that early, by inspecting a mask (or image) and telling you, as plain booleans, what state it's actually in.

It's from ComfyUI-WJNodes, a small personal utility pack - the author publishes only under the handle 807502278, and the whole pack reads like exactly what it is: tools built to solve the author's own recurring annoyances, this one clearly born from getting burned by a silently-broken mask at some point.

What it checks

Feed it a mask (or an image - if you give it both, it defaults to inspecting the image), and it runs a handful of sanity checks and returns each as a boolean, plus a numeric readout:

  • Exist? - is there actually a mask here, or is it uniformly one color? This is the headline check: a completely solid mask (whether black, white, or gray) means "nothing was detected here," and this is how you catch that programmatically instead of by eyeballing a preview.
  • HardEdge - is the mask strictly binary (pure 0/255 values), or does it have soft, feathered edges?
  • PureWhite / PureBlack / PureGray - the three specific "this mask contains literally nothing useful" states, broken out individually so you can branch on exactly which failure mode you're seeing.
  • PureColorValue - if the input turns out to be a single solid color, this outputs that value (0–255). If it's not a single flat color, this comes back as 0.

Two inputs tune the sensitivity of these checks: accuracy (default 255, the color-comparison precision) and Exist_threshold (default 3, how much variation counts as "a mask exists" rather than being written off as noise).

Why you'd actually wire this in

The obvious use is a gate: run your detection/masking step, check Exist? with this node, and only proceed to the expensive part of the pipeline - a sampling pass, an inpaint, a video-wide detailer run - if there's genuinely something to work on. That saves real compute on automated batch jobs where you can't manually eyeball every frame or every generated mask before committing to the next step.

The less obvious use is debugging. If a workflow produces unexpected results downstream of a mask-generating step, wiring this node in temporarily and checking what it reports is a faster way to find "the mask was empty the whole time" than staring at a black square in a preview and assuming it's supposed to look like that.

Installing it

ComfyUI Manager: search "ComfyUI-WJNodes." Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-WJNodes.git

Restart ComfyUI. No models, no heavy dependencies - this is straightforward pixel-value inspection.

Where to be careful

The accuracy and Exist_threshold defaults are conservative - they're tuned to catch genuinely flat, useless masks rather than masks that are merely low-contrast. A real but very faint or very small mask region can still register as "exists" correctly at the defaults, but if you're working with unusually subtle masks (very low opacity, tiny regions), you may need to loosen Exist_threshold to avoid false negatives. There's no community discussion of tuned values for specific use cases anywhere - this pack has essentially no public footprint - so the practical approach is to test against a known-good and a known-empty mask from your own pipeline and confirm the defaults actually distinguish them before relying on this as an automated gate.

CategoryWJNode/GetData

Inputs (4)

NameTypeDefaultDescription
accuracyINT2552–255
Exist_thresholdINT32–255
imageoptIMAGE
maskoptMASK

Outputs (6)

NameTypeDescription
Exist?BOOLEAN
HardEdgeBOOLEAN
PureWhiteBOOLEAN
PureBlackBOOLEAN
PureGrayBOOLEAN
PureColorValueint