Nodes/ComfyUI-Rect/Rect / Mask
ComfyUI Node

Rect / Mask

The fastest road to a clean inpainting mask in ComfyUI

By jtrue·Created about a year ago·Updated about a year ago· 3
Rect / Mask
  • image
  • rect
  • existing_mask
  • mask
feather0
invertfalse
combinereplace

If you've built one inpainting workflow in ComfyUI, you know the part that eats your time isn't the sampler - it's producing a usable mask. Drawing one by hand in an editor, saving it, importing it, hoping the resolution lines up... Rect / Mask collapses that into two nodes: draw a box with Rect / Select, and out comes a clean 0..1 MASK tensor, with feathering, inversion, and boolean combining built in. For anything where the region is roughly rectangular, it's the fastest mask you'll ever make.

How it works

The node builds a binary mask at your image's exact resolution, so there's no resize mismatch waiting to bite you downstream. Then, in order: it feathers the edges with a Gaussian blur (feather pixels, roughly a radius/2.5 sigma - a soft gradient rather than a hard edge), optionally inverts the whole thing, and finally combines it with an existing_mask if you've wired one in. The combine step is proper boolean math - union (max), intersect (min), subtract, and multiply - so you can stack a rectangle on top of an existing painted mask instead of starting over.

One quiet detail worth appreciating: it's tolerant of other packs' messy mask shapes. If the existing_mask comes in as [H, W], [B, H, W], or some weird [B, 1, H, 1] hybrid, it normalizes the shape and resizes spatial mismatches with bilinear interpolation. In other words, it just works when the thing feeding it doesn't.

Inputs that matter

  • image + rect - the image defines the mask's resolution; the rectangle defines the region.
  • feather - pixels of edge softness. Start around 4–12 px; that's the sweet spot for inpainting. Zero gives you a hard-edged box, which is what you want for compositing but a seam factory for generation.
  • invert - flip the box from "mask inside" to "mask everything outside." Handy when you want to protect a region instead of edit it.
  • combine - how the new rectangle merges with existing_mask when it's connected.

The single output, mask (a MASK), wires into the usual suspects: Set Latent Noise Mask + VAE Encode for classic inpainting, or any mask-aware node (regional prompting, ControlNet, detail fixing).

Why a box mask still earns its keep

If you've moved most editing to whole-image instruction models like Qwen-Image-Edit or Flux Kontext, you might wonder if masks still matter. They do, in exactly the cases those models can't touch. A mask means the rest of the image stays bit-identical - no edit model can promise that. It means you can render just the masked region at full native resolution and paste it back. And it gives you the denoise dial, a continuum of control no sentence can match. For precision work, rectangle-in, mask-out is still the workflow. This node is the fastest on-ramp to it.

Install

ComfyUI Manager (search "ComfyUI-Rect") or:

cd ComfyUI/custom_nodes
git clone https://github.com/jtrue/ComfyUI-Rect

Restart. No models to download, no requirements.txt, no dependency roulette - pure PyTorch start to finish.

Gotchas

  • replace ignores your existing mask. If you wire in an existing_mask but leave combine on its default of "replace", the new rectangle just replaces everything and your existing mask does nothing. Switch to union if you meant to keep both.
  • Big feathers wash the mask out. A huge feather value on a small box turns the whole rectangle into a soft gray smear. Keep it modest relative to the box size.
  • The RECT type. As with the rest of the pack, rect comes from Rect / Select. There's no way to type a rectangle directly into this node - draw it once, reuse it everywhere.

For "mask this region" inpainting, Rect / Mask plus Rect / Select is the two-node combo you'll reach for before you ever open a pixel editor again.

CategoryRect

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
rectRECT
featherINT00–256
invertBOOLEANfalse
combineSTRINGreplace
existing_maskoptMASK

Outputs (1)

NameTypeDescription
maskMASK