Nodes/ComfyUI-TinyBee/Rect Inside Image
ComfyUI Node

Rect Inside Image

Is your crop box actually inside the image? Get the full edge report.

By TinyBeeman·Created about a year ago·Updated 10 days ago· 1
Rect Inside Image
  • image
  • tinyrect
  • allInset
  • allOutset
  • allFlush
  • someInset
  • someOutset
  • someFlush
  • leftInset
  • leftOutset
  • leftFlush
  • topInset
  • topOutset
  • topFlush
  • rightInset
  • rightOutset
  • rightFlush
  • bottomInset
  • bottomOutset
  • bottomFlush
tolerance_pct0

Detectors overshoot. A Florence2 or SAM box routinely pokes a few pixels past the image edge, and a rect that hangs off the canvas breaks crops, breaks masks, and makes detailers do strange things. Rect Inside Image is the diagnostic that tells you exactly how your rectangle relates to the image boundary - not as a vague "it's fine" but as an 18-boolean report card covering every side and every aggregate.

The mechanism is edge arithmetic with a tolerance: for each side (left, top, right, bottom) it classifies the rect edge as inset (strictly inside the image), outset (past the edge), or flush (right on it, within tolerance_pct). Then it rolls those up into allInset / allOutset / allFlush (every side agrees) and someInset / someOutset / someFlush (at least one side does). The tolerance is a percentage of the image dimension, so 1 at 1024px wide means "within ~10 pixels counts as flush" - handy when a detector's slop is smaller than your patience.

The inputs and the outputs you'll actually read

  • image and tinyrect - the canvas and the box under test.
  • tolerance_pct - default 0.0. This is the input worth touching: raise it if you keep getting *Outset flags for sub-pixel overshoot you don't care about.

The full 18-boolean output (allInset, someFlush, leftOutset, topInset, and so on) is more than you'll need most days, and that's the point - you pick the one that gates your logic. The two that matter in practice: allInset (safe to crop-and-detail in place) and someOutset or any side-specific leftOutset/topOutset etc. (the region touches or crosses an edge, so a plain crop would cut it off). Wire allInset into a boolean switch to route edge-crossing boxes to a grow node like Change Rect Aspect or Crop/Grow Image to Bounds instead of a blind crop.

Install and gotchas

It's part of ComfyUI-TinyBee, installed all at once:

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

or ComfyUI Manager → "ComfyUI-TinyBee" → restart. No models, pure comparisons, instant. The gotcha is naming, not behavior: this node reports geometry - it does not move the rect or fix anything. If you wire its outputs straight into a crop expecting correction, you'll get nothing; it's a test node, and the correction lives in the pack's other rect nodes. It sits in 🐝TinyBee/Rectangles, and it's the one you reach for when a crop comes out half-black and you want proof of why in one glance.

Category🐝TinyBee/Rectangles

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
tinyrectTINYRECT
tolerance_pctFLOAT00–100

Outputs (18)

NameTypeDescription
allInsetBOOLEAN
allOutsetBOOLEAN
allFlushBOOLEAN
someInsetBOOLEAN
someOutsetBOOLEAN
someFlushBOOLEAN
leftInsetBOOLEAN
leftOutsetBOOLEAN
leftFlushBOOLEAN
topInsetBOOLEAN
topOutsetBOOLEAN
topFlushBOOLEAN
rightInsetBOOLEAN
rightOutsetBOOLEAN
rightFlushBOOLEAN
bottomInsetBOOLEAN
bottomOutsetBOOLEAN
bottomFlushBOOLEAN