Nodes/RES4LYF/Mask Bounding Box Aspect Ratio
ComfyUI Node Runs on cloud

Mask Bounding Box Aspect Ratio

Crop to a mask at the ratio you want

By ClownsharkBatwing·Created 2 years ago·Updated 22 days ago· 1,222
Mask Bounding Box Aspect Ratio
  • image
  • mask
  • image
  • mask
  • mask_blurred
  • x
  • y
  • width
  • height
padding0
blur0
aspect_ratio1.00
transposefalse

This is an inpainting/detailing helper. Give it a mask, and it finds the tight rectangle around the masked region, expands that rectangle to a target aspect ratio, and hands you back the cropped image plus the crop's exact coordinates. That last part is the point: because it returns the x, y, width, and height it used, you can process the crop (inpaint it, run a detailer on it, upscale it) and then paste it back into the original image at precisely the right spot. It's the "crop → fix → stitch" pattern that makes region-based editing efficient instead of re-rendering the whole frame.

It ships in RES4LYF (by ClownsharkBatwing) - a pack mostly famous for flow-matching samplers, but which carries workflow utilities too. Tellingly, this node's category is essentials/mask, the naming convention of the popular ComfyUI Essentials pack, so if you've used that ecosystem it'll feel familiar.

Why crop to an aspect ratio at all

Because models generate best at the resolutions and shapes they were trained on. A raw mask bounding box is whatever shape the masked area happens to be - often a weird sliver. Forcing it to a sane aspect ratio (1:1, 3:4, 16:9) before you sample into it means the inpaint or detailer works on a well-proportioned tile the model actually likes, which is the difference between a clean fix and a warped one. The padding gives the model context around the edit so the result blends; the blur softens the mask so the seam disappears when you composite back.

The inputs and outputs

  • mask (optional MASK) - the region to bound. This is what drives the crop.
  • image (optional IMAGE) - the source to crop from.
  • aspect_ratio (default 1.0) - the target ratio the box is expanded to. 1.0 is square; set it to match your inpaint tile.
  • padding (default 0) - pixels added around the box, for blend context. A little padding almost always helps.
  • blur (default 0) - softens the mask edge; feeds the separate mask_blurred output.
  • transpose (default false) - flips the ratio's orientation (portrait ↔ landscape) when the region's shape calls for it.

Outputs: image (the crop), mask and mask_blurred (sharp and softened, for compositing), and x, y, width, height - the four integers you feed a paste/stitch node to put the processed crop back exactly where it came from.

Installing it

ComfyUI Manager: search RES4LYF, install, restart. Or manually: cd ComfyUI/custom_nodes && git clone https://github.com/ClownsharkBatwing/RES4LYF, then cd RES4LYF && pip install -r requirements.txt in your venv (portable ComfyUI uses its embedded pip). Restart, hard-refresh F5. No models.

Where people get burned

  • Forgetting to stitch back. The x/y/width/height outputs exist so you can composite the fixed crop into the original. Skip that and you've just got a floating cropped patch.
  • Zero padding, hard seam. With padding 0 and blur 0 the pasted region can show a visible edge. Add a few px of padding and a little blur (use the mask_blurred output for the composite) and it vanishes.
  • Ratio vs region mismatch. A tall thin mask forced to 1:1 grabs a lot of surrounding image. Either pick an aspect ratio close to the region's real shape or use transpose so the box grows the sensible way.
  • Two nodes, same name. Because it lives under essentials/mask, workflows built for the actual ComfyUI Essentials node may resolve to a different one. If a graph specifically wants the RES4LYF version, install RES4LYF.
Categoryessentials/mask

Inputs (6)

NameTypeDefaultDescription
paddingINT00–4096
blurINT00–256
aspect_ratioFLOAT1.000.01–10
transposeBOOLEANfalse
imageoptIMAGE
maskoptMASK

Outputs (7)

NameTypeDescription
imageIMAGE
maskMASK
mask_blurredMASK
xINT
yINT
widthINT
heightINT