Nodes/ComfyUI-UtilsCollection/Adjust Bounding Box
ComfyUI Node

Adjust Bounding Box

Expand a bounding box around its center, cleanly

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Adjust Bounding Box
  • input_data
  • bounding_box
index0
pixel_expansion0
expansion_axisboth
size_multiple0

Bounding boxes are the connective tissue of inpainting, cropping, and regional workflows, and the moment you start doing them programmatically you'll want one thing: a box that grew a little bit without moving. Detector boxes hug their subject tightly, and tight boxes produce crops that clip hair, margins that sample edge artifacts, and inpainting regions that don't include the context the model needs. UC_AdjustBoundingBox is the small utility that fixes that - it expands a selected box around its center and optionally rounds its size to a pixel multiple, so it plays nicely with samplers that want aligned dimensions.

What it does

Feed it input_data in the form this pack's UC_ExtractBoundingBox accepts - a native box, a JSON string, a list, a dict, or a nested structure - pick index (default 0) to select which box when there's more than one, and get a BOUNDING_BOX out with x, y, width, height.

The controls are few and each does one thing:

  • pixel_expansion - pixels added to each selected edge, around the center. Default 0; 16 or 32 are the usual starting points.
  • expansion_axis - both (default), horizontal, or vertical. Feed the expansion only to the axes that need breathing room.
  • size_multiple - a combo of 0, 8, 16, 32. Round width and height up to this multiple while keeping the box centered; 0 disables alignment. Set it to 16 and your crop/region dimensions stay friendly to the VAE's tile grid.

The math is genuinely centered - it grows both sides equally, and when rounding, it distributes the extra pixels symmetrically so the box doesn't drift. That "keeps it centered" property is the whole point: an uncentered expansion will make your inpainting region slide off the subject by half your padding.

There's one built-in guard worth knowing: if the selected box has zero or negative width or height, the node raises a clear error rather than silently producing garbage. You'll see that when you pass it a degenerate box - usually a sign the detector upstream collapsed something.

Install

Via ComfyUI Manager (search ComfyUI-UtilsCollection) or:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart. Deps are opencv-python and typing-extensions; nothing downloads.

When you'd reach for it

Right after a detection node hands you a too-tight box: expand by 10–20% around the center so your crop includes context, then align to a multiple so the downstream sampler doesn't complain. It's a boring utility that earns its keep the first time you chain it between UC_ExtractBoundingBox and a crop or inpaint node. If the box you want doesn't exist yet, pair it with the pack's Extract Bounding Box node to build one from scratch.

Categoryutils/primitive

Inputs (5)

NameTypeDefaultDescription
input_data*Bounding-box data accepted by Extract Bounding Box: a native box, JSON string, list, dict, or nested structure.
indexINT00–9223372036854776000Index of the bounding box to adjust.
pixel_expansionINT00–9223372036854776000Pixels added to each selected edge. Both adds this value on all four sides.
expansion_axisCOMBObothChoose which axes receive the explicit pixel expansion.
size_multipleCOMBO0Round width and height upward to this multiple while keeping the box centered. Zero disables alignment.

Outputs (1)

NameTypeDescription
bounding_boxBOUNDING_BOX