LayerUtility: RestoreCropBox V2
Put the crop back where it came from
- background_image
- croped_image
- crop_box
- croped_mask
- image
- mask
The crop-restore pattern is one of the most useful things in image work: crop to the subject, do heavy processing on the small region (detail upscale, face fix, inpaint), then paste the improved result back into the original frame at exactly the right spot. RestoreCropBox V2 is the "paste back" half of that. You feed it the original background, the processed crop, and the crop box you saved earlier, and it composites the crop back into the frame - with an optional feathered edge so the patch doesn't look like a hard sticker.
It's a port of the LayerStyle/RunningHub-family node, sitting in the RunningHub/LayerUtility category of the ComfyUI_Swwan pack. The V2 here adds two things over the plain version: feathering (a Gaussian-blurred mask edge that hides seams and color fringing) and a device choice so the feathering can run on GPU for video batches.
Inputs and outputs
Required: background_image (the original full image), croped_image (the processed crop, yes it's spelled "croped" in the schema), invert_mask, crop_box (a BOX value - same box that the pack's CropByMask V4 or any crop node output), feathering (0–256, default 0), and device (CPU/GPU). Optional: croped_mask - if you have a mask that should control what gets pasted (e.g. only paste the inpainted region, not the whole crop rectangle), hand it in.
Outputs: the composited image and a mask showing exactly where the paste happened (black elsewhere, the feathered patch region in white). That mask is handy if you want to feed the paste location to other nodes, or inspect what got touched.
How it works
It converts both images to PIL, takes the layer's alpha (or your provided mask, inverted per invert_mask), optionally blurs it with a Gaussian kernel sized from feathering - kernel radius = feathering × 2, sigma = feathering / 3 - then pastes the crop onto the background at the crop_box coordinates. The feathering is the V2 star: at 0 it's a hard rectangular paste, at 20–40 you get a soft transition that hides the seam. For batch inputs it pairs background/crop/mask item-by-item, repeating the last of any shorter list.
Installing it
It ships in ComfyUI_Swwan:
cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
pip install -r ComfyUI_Swwan/requirements.txt
Or via ComfyUI Manager, search "ComfyUI_Swwan".
Where people get burned
The box has to match the crop. If you restore with a different box than the one used to crop, the paste lands in the wrong place or at the wrong size - the classic failure after a crop node's aspect-ratio handling changed the dimensions. Keep the crop box from the same node that made the crop, and re-verify if you switch crop nodes mid-workflow. Feathering also costs: on big images with a large radius it's a real convolution, so keep device on GPU for frame sequences. And a bare crop pasted at feather 0 will show a visible edge on any gradient background - if you see the seam, that's the parameter to raise, not a bug.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| background_image | IMAGE | — | |
| croped_image | IMAGE | — | |
| invert_mask | BOOLEAN | false | — |
| crop_box | BOX | — | |
| feathering | INT | 00–256 | — |
| device | COMBO | CPU | 2 options: CPU, GPU |
| croped_maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |