Nodes/tri3d-comfyui-nodes/Stitch box to image v5.1.0
ComfyUI Node

Stitch box to image v5.1.0

Paste the regenerated crop back where it came from

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Stitch box to image v5.1.0
  • image
  • mask
  • box
  • IMAGE

Stitch box to image is the "put it back" half of a crop-edit-paste loop. The pack's other half, tri3d-image-mask-2-box, cuts a region out of an image using a mask's bounding box so you can edit it in isolation; this node reverses the operation. It takes the original image, the mask you used, and the edited patch, finds the bounding box of that mask, and drops the patch back into exactly the right spot. One IMAGE out, the repaired frame.

The mechanism is one line of honest pixel math: get_bounding_box finds the mask's min/max rows and columns, and the patch is assigned into that slice of the original. No blending, no feathering, no alpha - a hard rectangular paste. That's a feature as much as a limitation: it's deterministic, and you know precisely what you're getting. Soft edges are your job (the pack's tri3d_fill_mask neighbor-fill is a decent partner for tidying the seam afterward).

Inputs

  • image - the original full frame.
  • mask - the same mask you used to extract the box. The bounding box is recomputed from it here, so it must match the extraction step or the paste lands in the wrong place.
  • box - the edited patch (usually the output of the node that regenerated or recolored the crop).

Output

One IMAGE - the original with the patch stitched back in.

Where it earns its keep

This is the workhorse of region-based workflows: crop a garment or a face, run it through a focused inpaint or recolor pass at higher effective resolution, then stitch it back while the rest of the frame stays untouched. It's also how you'd reassemble after the pack's pose-part extraction - crop around a body part, fix it, paste it home. The pattern keeps edits surgical and cheap instead of regenerating whole frames.

Install

Same pack, same story:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
# restart ComfyUI

Or via ComfyUI Manager (search "tri3d"). Keep the folder named tri3d-comfyui-nodes. OpenCV/numpy only - no models, no extra dependencies, instant on CPU.

Gotchas

  • The paste is hard-edged and exactly mask-sized. If your patch was resized or your mask changed between extract and stitch, you get a visibly misaligned rectangle. Keep the mask identical across both steps.
  • It pastes the patch at the mask's bounding box - the patch is expected to be that box's contents. If you feed it something bigger or smaller, it'll clip or stretch silently. Don't feed it a different-size crop.
  • If the mask is empty (all black), get_bounding_box falls back to the full image dimensions - an empty mask pastes the patch over the whole frame, which is almost never what you meant. Check your mask if the output looks catastrophically wrong.

Boring, deterministic, and exactly what the crop-edit-paste pattern needs. In this pack's pipelines it's the closing parenthesis on almost every region edit.

CategoryTRI3D

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
boxIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE