Nodes/ComfyUI-xiaozhuguang/小珠光 ATR (图像回贴)
ComfyUI Node

小珠光 ATR (图像回贴)

The paste-back node that completes the crop-refine loop

By xiaozhuguang·Created 2 months ago·Updated a day ago· 56
小珠光 ATR (图像回贴)
  • original_image
  • processed_image
  • crop_box
  • mask
  • restored_image
blur_amount0
mask_expand0

Here's the thing nobody tells you about the "zoom in, re-render, zoom out" trick: the paste-back is where a workflow either looks like magic or looks like a sticker. 小珠光 ATR ("图像回贴", image re-paste) is the half of that loop that most crop-refine pipelines gloss over - it takes your processed sub-image and sticks it back onto the original at exactly the right spot, with feathering controls to hide the seam.

You know the loop from the automatic-detailing docs: detect a region, crop it, run a fresh sampling pass at full resolution, composite it back. Impact Pack's SEGSPaste does the composite half for SEGS; ATR is the same idea but simpler - it doesn't care about SEGS or detectors at all. You hand it the original, the processed crop, and a CROPBOX saying where the crop came from, and it handles the rest.

How it works

ATR takes the crop_box (the CROPBOX that the pack's ATBC node emits) and uses the coordinates inside it - including the padding and fill info ATBC recorded - to know exactly where the processed image belongs on the original canvas. It resizes your processed_image back to the crop region's original dimensions and composites it in. The code is OpenCV + numpy throughout, so it's fast even across a batch of frames.

The seam controls are the interesting part. blur_amount applies a Gaussian blur to the mask (or bbox) edge, feathering the boundary so the paste blends rather than cutting. mask_expand grows (positive) or shrinks (negative) the paste region before compositing - handy when your re-render came out slightly too small and you want to bleed it out a bit. And if you have the actual mask that defined the crop in the first place, connect it: ATR uses a mask-weighted blend instead of a hard rectangle paste, which is the difference between a soft face edge and a visible box around it.

The inputs that matter

  • original_image and processed_image - the untouched original, and whatever you did to the crop.
  • crop_box - the CROPBOX from ATBC. This is the glue that makes the whole thing work; don't hand-build it yourself.
  • blur_amount - the seam-killer. Start at 0, and only raise it if you see a hard edge.
  • mask_expand - negative values shrink the paste; useful for leaving a hairline of original around the re-render.

Output is a single restored_image (IMAGE) - the original with the processed region composited in.

When you'd reach for it

Any time you re-render a crop and need it back in place: upscale a face crop, run img2img on it, paste it back at native resolution. Same for editing a region and compositing it into the full frame. The one honest caveat from the detailing world applies here too - if the region didn't need re-rendering, the paste is just extra steps and a new seam to hide. Use it where the crop genuinely bought you resolution.

Install

Part of the ComfyUI-xiaozhuguang pack. Manager (search "ComfyUI-xiaozhuguang"), or:

cd ComfyUI/custom_nodes/
git clone https://github.com/xiaozhuguang/ComfyUI-xiaozhuguang.git

Restart after. No models, no heavy dependencies - just OpenCV, which ComfyUI already pulls in.

Gotcha

The easiest way to break ATR is to feed it a crop_box that doesn't match the original_image - say you cropped from a resized copy and pasted that box onto the full-res original. ATBC and ATR are designed to be wired together, and they record the original size and padding inside the CROPBOX precisely so the round-trip lines up. Keep that wire intact and the geometry sorts itself out.

Categoryxiaozhuguang

Inputs (6)

NameTypeDefaultDescription
original_imageIMAGE
processed_imageIMAGE
crop_boxCROPBOX
blur_amountINT00–500边缘羽化值,对mask边缘或bbox边缘应用高斯模糊
mask_expandINT0-500–500遮罩扩展值,正值扩展,负值收缩
maskoptMASK

Outputs (1)

NameTypeDescription
restored_imageIMAGE