Nodes/ComfyUI-TextureAlchemy/Scale Image to Reference Bbox ⚡
ComfyUI Node

Scale Image to Reference Bbox ⚡

The fix when your inpainted crop won't line back up

By amtarr·Created 9 months ago·Updated 4 months ago· 58
Scale Image to Reference Bbox ⚡
  • image
  • mask
  • reference_bbox
  • image
  • mask
  • bbox_data
  • info
canvasreference_size
match_modelarger_side
padding0
invert_maskfalse

If you've ever cropped to a mask, generated an edit, and then watched the result land back on the original at the wrong size and wrong place, you know the pain this node exists to kill. Scale Image to Reference Bbox rescales an image and its mask so that the subject fills exactly the width and height a reference bounding box promises. It's part of the Texture Alchemy inpainting family: crop → edit → this → stitch.

What it actually does

The mechanism is simple and honest. You feed it an image, a mask, and a reference_bbox (grab one from the bbox_data output of a crop node like Simple Inpaint Crop). It finds the mask's bounding box, computes the ratio between that box and the reference W×H, and uniformly scales the whole image up or down so the subject matches. Then, because the default canvas is reference_size, it centers that scaled frame in an output that's exactly the reference dimensions - a stitch window. Paste that into the original with Simple Inpaint Stitch and things line up.

The scaling mode you actually set is match_mode:

  • larger_side (default) - max of the width and height ratios. This is the right call when your edit came back undersized and you want it to fully cover the target.
  • smaller_side - min of the ratios, good for fitting something inside a region.
  • width / height - match one axis only.
  • area - scale by the square root of the area ratio; the most "neutral" pick if you don't know the aspect ratio behavior.

Also worth knowing: padding expands the mask bbox before scaling, and invert_mask flips which side of the mask counts as the subject - handy when your mask happened to be negative-space.

Inputs and outputs that matter

Required inputs are image, mask, and reference_bbox. The outputs are image, mask, plus bbox_data and an info string - the bbox bundle can be threaded straight into a stitch node, and info is a text summary you can drop into a Show Text node or just read in the console.

Installing it

This ships in the amtarr/ComfyUI-TextureAlchemy pack ("Texture Alchemy"). In ComfyUI Manager, search "Texture Alchemy" and hit install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/amtarr/ComfyUI-TextureAlchemy

Restart ComfyUI, then right-click → Add Node → Texture Alchemist → Inpainting. No extra Python packages and no model downloads - the whole pack runs on PyTorch, PIL and NumPy, which ComfyUI already has. One heads-up: these nodes are chatty and print a log banner to the console every run. That's normal, not an error.

Where people get burned

An empty or all-black mask makes the node shrug and return your image unchanged with scale 1.0 - so if nothing happens, check the mask. And if the subject still isn't centered, remember the output is centered on the mask bbox, not the image center. The pack is niche and you won't find much community lore about it; when in doubt, leave canvas at reference_size and adjust match_mode first.

CategoryTexture Alchemist/Inpainting

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
maskMASK
reference_bboxBBOX_DATA
canvasCOMBOreference_sizereference_size: output exactly ref W×H (stitch-friendly); scaled frame centered on subject. scaled_full: entire scaled image (W×S, H×S)
match_modeCOMBOlarger_sidelarger_side=max(w,h ratios)—typical to match undersized edits; smaller_side=min; width/height=one axis; area=sqrt(ref area / src area)
paddingINT00–500Extra pixels around mask bbox before resize
invert_maskBOOLEANfalseInvert mask before bbox detection

Outputs (4)

NameTypeDescription
imageIMAGE
maskMASK
bbox_dataBBOX_DATA
infoSTRING