Light-Tool: Invert Mask
Inverts white and black — but it's an IMAGE node, and that's the catch
- image
- image
Half of mask debugging is flipping the convention. Your inpainting node wants white where the subject is, but your mask pipeline produced white for the background, or a background-removal pass handed you black-on-white when you needed white-on-black. Light-Tool: InvertMask flips every pixel, 255 minus value, black becomes white and white becomes black. Exactly the fix, one node.
But read the type signature before you wire anything into it, because the name is a half-truth. It takes image (an IMAGE) and returns image (an IMAGE). It does not accept a MASK tensor. ComfyUI's own InvertMask node exists precisely because MASK and IMAGE are different types in this ecosystem, and this node lives on the image side of that divide.
How it works. The image is converted to grayscale (mode L), then every pixel is replaced with 255 - current_value. Soft edges stay soft - a 30% gray pixel becomes 70% gray, so gradient masks invert gracefully rather than snapping. That's the right behavior for feathered masks and a pleasant surprise in a utility node.
The catch in practice. If you have a real MASK and you want it inverted, this node will refuse the connection on the canvas. Two workarounds: run it through this pack's MaskToImage first (MASK → IMAGE, then invert, then ImageToMask if you need a MASK back), or just use core ComfyUI's InvertMask, which handles the MASK type natively. Since most inpainting setups already have the stock node available, the honest advice is: this one earns its keep when your "mask" is actually a grayscale image - a cutout preview, a painted mask you saved as a PNG, an alpha channel extract - and you want it flipped without converting types.
Where it slots in. The classic pairing is with this pack's own nodes. ImageOverlay uses overlay * alpha + base * (1 - alpha), so a mask that's black where you want the overlay will composite backwards - invert it first. MaskImageToTransparent treats white as kept; if your mask arrived white-background/black-subject, same story. Once you're living inside the Light-Tool mask family, this node is the bridge that keeps conventions consistent.
Installing. Part of the pack, so install once:
cd ComfyUI/custom_nodes
git clone https://github.com/ihmily/ComfyUI-Light-Tool.git
pip install -r requirements.txt
# restart ComfyUI
Or via ComfyUI Manager: search ComfyUI-Light-Tool → Install → restart. No models to download.
One more thing. The pixel loop is pure Python - fine for typical sizes, and it runs fast enough you won't notice. The real thing to remember is the type: it says mask, it means image. Wire accordingly and it's a perfectly good utility; forget that and you'll get a red connection line and a moment of confusion that this article just saved you from.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |