Nodes/ComfyUI_Swwan/Restore Crop Box V3 (Batch)
ComfyUI Node

Restore Crop Box V3 (Batch)

The paste-back half of the crop-process-paste loop, now batch-safe

By aining2022·Created 9 months ago·Updated 10 days ago· 33
Restore Crop Box V3 (Batch)
  • background_image
  • croped_image
  • crop_box
  • croped_mask
  • image
  • mask
invert_maskfalse
feathering0
deviceCPU

Every crop has to come back. Crop By Mask cut a region out of a frame, you ran it through an inpaint or detail pass, and now you need to paste the result back onto the original - at the exact right position, with a feathered edge so there's no visible seam. That's this node: Restore Crop Box V3 is the paste-back half of the loop, and the "V3 (Batch)" means it handles whole video batches instead of one frame at a time.

The family pattern is Impact Pack's detect-crop-refine loop, just done explicitly: crop the region, process it, restore it. V3's job is the restore, and its specific contribution over the older versions is that it accepts video-sized batches directly - no converting to an image list first. You give it the original frames and the processed crop frames, both as batches, plus the crop box, and it pastes every frame.

Inputs and outputs

  • background_image (IMAGE) - your original frames. This is the canvas.
  • croped_image (IMAGE) - the processed crop frames to paste in. Batch size must match background_image exactly - V3 will raise a ValueError if they differ.
  • crop_box (BOX) - the [x1, y1, x2, y2] box from the crop node. One box is applied to every frame.
  • invert_mask (BOOLEAN, default false) - flips the paste mask. V3-only, and handy when your mask arrives with inverted semantics (ComfyUI masks love to be 1 - alpha).
  • feathering (INT, default 0, range 0–256) - the blur radius on the paste mask. Zero is a hard cut. The node's own guidance: 15–30 for low-res, 30–60 mid, 60–120 high-res.
  • device (CPU/GPU) - GPU moves the feathering math to the GPU. The paste itself is PIL-based, frame by frame.
  • croped_mask (MASK, optional) - supply your own paste mask instead of deriving one. If omitted, it uses the cropped image's alpha channel, or a full-white mask if there's no alpha.

Outputs:

  • image (IMAGE) - the composited result, same batch size as the background.
  • mask (MASK) - the paste mask laid out on the full canvas, so you can see exactly where and how it blended.

How it works

Per frame, it converts to PIL, builds the paste mask (your croped_mask, else alpha/white), applies the gaussian feather, and pastes the processed crop onto the background at crop_box using that mask. The mask output is the same paste mask positioned on the full frame - useful if you want to inspect or reuse the blend region.

Install

In ComfyUI_Swwan. ComfyUI Manager → search "ComfyUI_Swwan", or:

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

Restart, then Restore Crop Box V3 (Batch) under Swwan/Image.

The gotchas

The exact-batch-size rule is the one that bites. Background has 30 frames, your crop path produced 29 (or worse, 1), and this node refuses with a ValueError - by design. It won't guess. If you're applying a single processed result to a whole video, that's what V4's auto-expand is for; V3 wants one-for-one.

Second, feathering at zero gives you hard edges that show up as a visible rectangle when the processed region doesn't perfectly match the background. Start with a feather matching your resolution (30–60 is a decent default for 1024-ish work) and only drop to zero when the crop is meant to be a hard composite.

Third, the invert_mask gotcha: if your pasted result looks like the hole is being filled and the subject is vanishing, your mask is inverted. Flip invert_mask and re-run - it's a one-click fix, which is exactly why V3 has the toggle and its faster sibling doesn't.

CategorySwwan/Image

Inputs (7)

NameTypeDefaultDescription
background_imageIMAGE
croped_imageIMAGE
invert_maskBOOLEANfalse
crop_boxBOX
featheringINT00–256
deviceCOMBOCPU2 options: CPU, GPU
croped_maskoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK