Unary Mask Op
Invert, round, clamp and average a mask in one node
- image
- IMAGE
This is the node you reach for when a mask is almost right and just needs simple math done to it - flip it, clean it up, force it into a sane range. No model, no inference, just a five-way switch over per-pixel arithmetic. If you've ever stared at a mask output and thought "I just need this inverted" or "this needs to be binary, not a gradient," this is the one-node fix instead of a sub-graph.
Where it fits
Masquerade Nodes is an older pack - built as a dependency-free mask toolkit back before ComfyUI Manager existed and made installing dependencies painless. The author's own README now says plainly that unless you specifically need zero dependencies, reach for Impact Pack instead for the heavy lifting (face/hand detection and detailing). But Impact Pack solves a different problem - detect, crop, resample. Masquerade Nodes is about mask arithmetic: combining masks, cutting and pasting by mask, cleaning up whatever a masking step handed you. Unary Mask Op is the cleanup utility in that toolkit.
The pack's headline node, Mask By Text, generates masks from a text prompt via ClipSeg - conceptually the ancestor of the VLM-grounded masking people do today (point a model at the image, get a region, build a mask from it). ClipSeg's raw output is a continuous 0–1 confidence map, not a clean binary mask, and that's exactly the kind of output Unary Mask Op was built to tidy up.
How it works
One input mask, one operation, one output mask - a straight per-pixel transform, no neighboring-pixel awareness (that's what Mask Morphology, a sibling node in this pack, is for). Internally this pack predates ComfyUI's native MASK socket type, so it represents a mask as a single-channel image tensor and converts channel counts automatically wherever needed - that's why the required input is literally named image even though what you're feeding it is a mask.
Inputs and outputs that matter
image- the mask to operate on (namedimagein the schema; per the pack's own docs, this is "the mask to operate on").op- one of five operations:invert- flips the mask (1 becomes 0, 0 becomes 1).average- replaces every pixel with the average value across the whole mask. Sounds pointless until you need it: feed it the raw ClipSeg output for two different prompts and average each, and you can compare which concept the image more strongly matches - a cheap "which one is it" check without thresholding first.round- rounds every pixel to the nearest integer, which for a 0–1 mask means binarizing at the 0.5 point. This is the one you'll use most: turn a soft, probabilistic mask into a clean 0-or-1 mask before cutting or compositing with it.clamp- forces every value back into 0–1. Useful after any math that can overshoot, like anaddin Combine Masks, which can legitimately produce values above 1.abs- takes the absolute value. Handy after adifferenceoperation that could dip negative.
Output is a single mask, ready to feed into Cut By Mask, Paste By Mask, Combine Masks, or any sampler's mask input.
How to install it
Via ComfyUI Manager: search "Masquerade Nodes," install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui
then restart. Unary Mask Op needs nothing beyond what ComfyUI already ships - no models, no extra packages. The one real dependency anywhere in the pack is ClipSeg, and it's only pulled in when Mask By Text runs, so installing for a utility node like this one won't trip it.
Common issues & troubleshooting
Nothing seems to change. Double-check you picked the operation you meant - round and clamp look similar in effect on an already-mostly-binary mask, so if your mask was already clean, either op will look like a no-op. Test on a genuinely soft/gradient mask first (raw ClipSeg output is a good one) to see the difference.
Your composite has hard, ugly edges after round. That's the point of the op - it's a hard threshold. If you wanted soft edges preserved, don't round; use Mask Morphology's open/close for cleanup instead, or blur before you round.
Values look wrong after chaining several mask nodes. Combine Masks with add or similar operations can push values outside 0–1 without you noticing, and a lot of downstream nodes assume a proper 0–1 range. Drop a clamp in the chain as cheap insurance before it reaches your sampler or a Cut/Paste By Mask node.
Installed the pack and this node is missing entirely. That's a pack-load failure, not a node-specific one - check your ComfyUI console on startup for an import error from masquerade-nodes-comfyui, usually a stale or partial clone. A fresh git pull and restart clears it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| op | COMBO | 5 options: invert, average, round, clamp, abs |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |