Nodes/ComfyUI-TinyBee/Rect To Mask
ComfyUI Node

Rect To Mask

Your detection box, turned into a mask the sampler actually accepts

By TinyBeeman·Created about a year ago·Updated 10 days ago· 1
Rect To Mask
  • tinyrect
  • mask
width512
height512
invertfalse
uvRectfalse

Detectors are great at finding things and terrible at telling ComfyUI where they found them in a form the sampler cares about. The sampler cares about masks - [H, W] tensors where 1 means "this pixel is in the region." A bounding box is just a rectangle, so the bridge is trivial: fill the box with 1s and the rest with 0s. That's Rect To Mask, and it's the node that turns "detector said the face is here" into "inpaint exactly here."

You give it a width, a height, and a TINYRECT, and out comes a MASK with that rectangle filled. Clamped to the canvas, so a rect that pokes outside the image just gets clipped instead of crashing. Negative widths or heights (some detector outputs are weird) get normalized before filling, too. It's deliberately dumb, and that's a feature - a rectangular mask is the honest shape of a bbox, and anything fancier (hugging a subject's outline) is what SAM-based masking is for.

The inputs and outputs that matter

  • width, height - the canvas size for the mask, defaults 512×512. Set these to your target resolution, which matters when the rect is normalized (see uvRect below).
  • tinyrect - the region, as a TINYRECT.
  • invert - flip it to fill everything except the box. Handy for masking out a region rather than masking in.
  • uvRect - the toggle that makes this node pair perfectly with Get UV Rect. Off (default) means the rect is in pixels. On means the rect is in 0-to-1 coordinates and gets multiplied by width/height first - so a normalized rect produces a correctly-scaled mask at any resolution you set. If you detected at one size and are masking at another, this is the switch that keeps everything aligned.

Output is a single mask (MASK), which feeds inpainting conditioning, detailer loops, or any mask-consuming node downstream.

Install and gotchas

It's part of ComfyUI-TinyBee, one install for the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/TinyBeeman/ComfyUI-TinyBee

or via ComfyUI Manager (search "ComfyUI-TinyBee") and restart. No models, no GPU load beyond the trivial fill - pure tensor construction. The classic mistake is feeding a normalized rect with uvRect off: the box collapses to a few pixels in the corner of the mask and your inpaint does nothing visible. Decide your coordinate space once, and use Get UV Rect + uvRect on whenever the pipeline resizes between detection and masking. It sits in 🐝TinyBee/Rectangles with the rest of the pack's geometry nodes.

Category🐝TinyBee/Rectangles

Inputs (5)

NameTypeDefaultDescription
widthINT5121–100000
heightINT5121–100000
tinyrectTINYRECT
invertBOOLEANfalse
uvRectBOOLEANfalse

Outputs (1)

NameTypeDescription
maskMASK