Nodes/BoxBox/🎨 BoxReinsert
ComfyUI Node

🎨 BoxReinsert

Stitch your edited region back so the rest of the image never moves

By mercu-loreΒ·Created 10 months agoΒ·Updated 7 months agoΒ· 3
🎨 BoxReinsert
  • original_image
  • generated_image
  • image
β—„box_metadataβ€”β–Ί
β—„resize_metadataβ€”β–Ί

BoxReinsert is the payoff node of the BoxBox pack - the "paste it back" step that makes local editing worth doing at all. You crop a region, resize it, run it through a generation or edit pass, and this node takes the result and drops it back exactly where the box was, leaving every pixel outside the box untouched.

That last part is the whole reason this workflow exists. Edit models like Qwen-Image-Edit or Flux Kontext regenerate the entire image, and the unedited areas come back close-but-not-identical; run a few edits in a row and the drift compounds. The crop-edit-stitch hybrid fixes it: only the region you boxed gets processed, the original pixels survive exactly, and you get the edit model's power without the degradation. That's the recipe the community converged on, and BoxBox is the manual, draw-a-box version of it. It pairs naturally with the camera-control and editing nodes mercu-lore builds for Qwen-Image-Edit.

How it works

BoxReinsert takes four inputs: original_image, generated_image, box_metadata (from BoxSelector), and resize_metadata (from BoxResize). It reads the box coordinates out of the metadata, applies the same displayScaleFactor correction as BoxCrop so the placement is right even on downscaled previews, then converts everything to PIL. If resize_metadata is present and valid, the generated image is resized with LANCZOS to exactly the crop box's dimensions before pasting; if it's empty, it's pasted as-is. The composited image goes back to a tensor, with RGBA/3-channel mismatches handled for you.

One thing to know: it operates on the first frame of each batch (image[0]), so for batched inputs only frame zero gets the reinsert. Single images are the intended use.

The output is a single image tensor - your original frame with the edited region composited in place. That goes straight to a SaveImage or PreviewImage.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/mercu-lore/BoxBox

Restart ComfyUI, or use Manager and search "BoxBox". The pack's requirements are just torch, numpy, and Pillow, so there's nothing extra to install and no models to fetch - a rare thing for a custom node.

The workflow, end to end

LoadImage β†’ BoxSelector ──box_metadata──→ BoxCrop β†’ BoxResize ──resize_metadata──→ [edit/generate] β†’ BoxReinsert β†’ SaveImage
                  └─────────────────────────────── original_image β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

BoxSelector feeds both the metadata and the untouched original; BoxResize's metadata tells the reinsert node how the generated output relates to the crop.

Common issues

  • Pasted region is the wrong size or distorted. BoxReinsert force-resizes the generated image to the crop box size, so if your edit pass produced a different aspect ratio than the crop, it gets squashed to fit. Keep keep_aspect_ratio on in BoxResize and generate at a size that matches the crop's proportions.
  • The edit landed in the wrong place. Check that box_metadata really came from BoxSelector and that you re-drew the box for the current image - the selector restores your last selection, which can quietly be from a previous image.
  • Nothing happened - output equals input. If box_metadata fails to parse, the node just returns the original image and logs an invalid-JSON warning. If you're seeing that, the metadata string isn't reaching this node; re-check the wiring.
Categoryimage/box

Inputs (4)

NameTypeDefaultDescription
original_imageIMAGEβ€”
generated_imageIMAGEβ€”
box_metadataSTRINGβ€”
resize_metadataSTRINGβ€”

Outputs (1)

NameTypeDescription
imageIMAGEβ€”