图片局部替换
Paste a patch back onto the canvas — LoadReplaceImage's mask blend
- image_t
- mask
- image_bt
- 图片
LoadReplaceImage (图片局部替换, "local image replacement") is the composite step in a crop-and-stitch pipeline. You give it a patch, a mask that says which part of the patch to keep, and a background image to paste onto - it blends the masked patch into the background at coordinates you choose, and hands you the composited result. No diffusion involved; it's pure pixel surgery.
Why reach for it: the crop-and-stitch trick is one of the most reliable ways to fix a small region at full detail. You crop an eye, run it through an inpaint or a detail pass at the model's native resolution, then paste the fixed crop back onto the original. That "paste back" step is exactly what this node does, and it does it inside the graph instead of in GIMP. The KB's inpainting essay calls exact-placement compositing one of the few things masked inpainting still owns over whole-frame edit models - this is that placement step, automated.
How it works
Internally it's a standard alpha blend. The mask gets resized to the patch's dimensions (it tolerates a mask that doesn't match), replicated into three channels, and then the node writes the masked patch into the background:
region = patch * mask + background_region * (1 - mask)
The x/y integers are the paste position. One quirk worth knowing: in the source, x slices rows (vertical offset) and y slices columns (horizontal), which is the reverse of what most people expect after years of (x, y) = horizontal, vertical. If your paste lands somewhere surprising, swap them.
Inputs and output
image_t- the patch/top image (the thing being pasted).mask- which pixels of the patch survive. Feed the same mask you used to crop, or a solid one to paste the whole patch.image_bt- the background/bottom image.x,y- paste offset (see the axis quirk above).- Output:
图片(image), the compositedIMAGE.
A safety valve in the code: if the mask shape doesn't match the patch, or the paste would run off the edge of the background, it silently returns the background unchanged. That's convenient - no crash - but it's also a silent no-op, so if your graph "does nothing," check your mask dimensions and coordinates first.
Install
Ships in yanlang0123/ComfyUI_Lam. Install via Manager (search "ComfyUI_Lam") or:
cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam
then restart. Pure numpy/torch, so it loads without the pack's heavy requirements - skip the README's install.bat if you're only here for the image utilities.
Where people get burned
Batch size mismatch is the classic. The blend runs on the smaller of the two batch counts (min_size), so if image_t has 4 frames and image_bt has 1, only frame 0 gets composited and the other three are dropped. Keep both batch counts aligned unless you intend that. And again - the axis swap. If the region lands in the wrong corner, swap x and y before you rebuild anything.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image_t | IMAGE | — | |
| mask | MASK | — | |
| image_bt | IMAGE | — | |
| x | INT | 00–99999 | — |
| y | INT | 00–99999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 图片 | IMAGE | — |