Nodes/ComfyUI-UniversalToolkit/Restore Crop Box (UTK)
ComfyUI Node

Restore Crop Box (UTK)

Paste a cropped-and-inpainted region back onto the original, box and all

By whmc76·Created about a year ago·Updated 2 months ago· 72
Restore Crop Box (UTK)
  • background_image
  • croped_image
  • crop_box
  • croped_mask
  • image
  • mask
invert_maskfalse

The most reliable way to inpaint a small region at high quality is to crop it, work on the crop at full resolution, then paste it back - that's the crop-and-stitch pattern the community standardized on for editing models, and it's still the trick that gets you bit-identical unmasked pixels. Restore Crop Box (UTK) is the "paste back" half of that. You hand it the original background, the cropped (and now processed) image, the crop box that says where it came from, and it composites the crop back into place.

It's part of ComfyUI-UniversalToolkit, and it's designed to pair with the pack's CropByMask_UTK node, which outputs a crop_box (a BOX - four integers (x1, y1, x2, y2)) along with the crop. Crop → process → restore, with the geometry carried in a wire instead of re-typed by you. That's the whole appeal: the box is data, not something you transcribe and get wrong.

How it works

You give it background_image (the original full frame), croped_image (the processed crop), and crop_box. The node creates a canvas the size of the background and pastes the crop at the box's coordinates. The optional croped_mask lets you control how much of the crop gets pasted - a soft mask means a feathered blend at the seam instead of a hard rectangle edge, which is how you hide the stitch line. invert_mask (default false) flips that mask's meaning if your mask convention is backwards.

It also outputs a mask showing exactly where it pasted - white over the restored region, black elsewhere. That's useful if you want to verify the geometry, or chain the result into another composite that needs to know the affected area.

A subtle nicety in the implementation: if no croped_mask is given, it builds a plain white mask the size of the crop, so the paste is full-strength. And it handles batches by pairing background frames with crops up to the longest list - if you feed fewer crops than backgrounds, the last crop is reused.

Inputs and outputs

  • background_image (IMAGE) - the original frame.
  • croped_image (IMAGE) - the processed crop.
  • crop_box (BOX) - where the crop belongs.
  • invert_mask (BOOLEAN) and croped_mask (MASK, optional).

Outputs: image (the restored composite) and mask (the paste region).

Install and gotchas

Install via ComfyUI Manager (search "ComfyUI-UniversalToolkit") or:

cd ComfyUI/custom_nodes
git clone https://github.com/whmc76/ComfyUI-UniversalToolkit
pip install -r requirements.txt

Restart ComfyUI. No models, no keys.

The traps are all geometry-adjacent. Feed a crop_box from a different image than the background_image and your crop lands in the wrong place silently - there's no validation that the box fits the background, so double-check you're not mixing sources. And if your crop went through a resize while being processed, its size no longer matches the box and the paste will misalign; resize it back to the box's dimensions before restoring. For the crop-and-stitch pattern this node nails, and the pair with CropByMask_UTK is worth building once and reusing.

CategoryUniversalToolkit/Image

Inputs (5)

NameTypeDefaultDescription
background_imageIMAGE
croped_imageIMAGE
invert_maskBOOLEANfalse
crop_boxBOX
croped_maskoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK