Nodes/ComfyUI_Element_easy/Smart merge images
ComfyUI Node

Smart merge images

The node that fixes pixel drift when Qwen-Edit or Klein edits your image

By supElement·Created 11 months ago·Updated a day ago· 14
Smart merge images
  • original_image
  • edited_crop_B
  • original_crop_A
  • split_grid
  • Merged_Image
◄warp_methodfalse►
◄optical_flowfalse►
◄use_tpstrue►
◄second_passfalse►
◄color_match▾►
◄feather_kernel20►
◄merge_mode▾►
◄use_gputrue►
◄force_recomputefalse►

Smart merge images is the flagship node of this pack, and it exists to solve a very 2026 problem: instruction editors like Qwen-Image-Edit and Flux 2 Klein don't patch your image - they re-emit the whole frame. Pixels you didn't ask to change come back slightly shifted, and the colors drift. So when you crop a region, edit it, and try to stitch it back onto the original, it doesn't line up. This node does the stitching for you: it finds the shared features between the edited crop and the original, warps them back into alignment, matches the color, and merges them into a seam-free result.

How it works

You feed it two images: original_image and edited_crop_B (the edited region to merge back). The node finds matching features between them, computes the transform that re-aligns the edit to the original, and blends. There's also an optional original_crop_A input - and the README's advice is worth taking: for the most reliable merge, use all three, where original_crop_A is the unmodified crop from the original image. That third input gives the matcher a clean reference and dramatically improves alignment.

The knobs are split into stages:

  • match_method - how features are found: SIFT (OpenCV) (fast, classic), or DISK + LightGlue / SIFT + LightGlue (learned matching, more robust).
  • warp_method - how the edit is realigned: Homography (affine-ish plane warp), Homography + Optical Flow, or pure Optical Flow for handling more complex distortion.
  • optical_flow - which flow estimator to use when flow is involved: Farneback, DIS, or RAFT-Small/RAFT-Large (the bigger, the more accurate, the slower).
  • color_match - nine modes including Histogram, LAB_Mean, SeamlessClone (PS Auto Blend), Laplacian Pyramid Blend, and the pack's own Adaptive Local (strong), which is specifically tuned to repair the color shift from editing models. This one has two companion knobs: adapt_thresh (color difference threshold) and adapt_local_match (which local matching flavor the adaptive mask fusion uses).
  • feather_kernel (0–256) - softness of the merge seam. merge_mode - One to One merges a single pair; All to One handles the tiled case.

use_gpu toggles GPU acceleration (default on - flip it off if you're getting VRAM pressure or crash-on-driver weirdness), and force_recompute re-runs the feature matching instead of reusing a cached result, which you'll want after changing inputs.

Tiled merging

v1.4.7 added support for merging multiple crops in one go: edited_crop_B can take a batch of crop images and the node returns a single fully merged Merged_Image. The catch, stated plainly in the README: the input must be a batch, not a list. If you're feeding it from a list-producing node, convert it first with an Image List To Batch node or it won't work.

The model download you should know about

Some of the advanced matching/color options need model files. They're optional - if you don't use those options, nothing downloads. When you do, the node auto-downloads them to ComfyUI/models/elementEasy on first run. If you'd rather pre-stage them (or you're offline), copy the elementEasy folder from the pack's models directory into that same path and it'll skip the download.

Installing it

It ships in supElement/ComfyUI_Element_easy:

cd ComfyUI/custom_nodes
git clone https://github.com/supElement/ComfyUI_Element_easy.git

Restart ComfyUI, or install via ComfyUI Manager by searching ComfyUI_Element_easy. This is the one node in the pack with real dependencies - OpenCV at minimum, plus the matching/flow machinery for the advanced modes - so expect the first run to be heavier than the rest of the pack.

Gotchas

The "batch not list" rule for tiled merging is the number one tripwire. After that: the merge only works when the images actually share enough common features - if the edit changed too much (completely new content, no overlap), there's nothing to align and the result will be rough. Start with SIFT (OpenCV) for speed and only escalate to LightGlue/RAFT when alignment is bad. And the Adaptive Local (strong) color mode is specifically the fix for Qwen-Edit-style color shift - if that's your problem, use it rather than the generic modes.

CategoryElement_easy/image

Inputs (13)

NameTypeDefaultDescription
original_imageIMAGE原始背景图(未编辑的完整图像)。All to One 模式下只有第一张会被使用。 原生支持 List / Batch / 单张输入(节点已声明 INPUT_IS_LIST, 引擎不会逐项展开), 无需外接 Image List To Image Batch。 -------------------------------------------------- Original background image(s) before editing. In 'All to One' mode only the first one is used. Natively accepts list / batch / single image (INPUT_IS_LIST declared, no per-item expansion) — no external 'Image List To Image Batch' node needed.
edited_crop_BIMAGEAI 编辑后的局部裁块(B), 将被对齐、畸变校正并贴回背景。可批量; 各裁块尺寸可不同(保持各自原始分辨率)。 原生支持 List / Batch / 单张输入, 多个裁块在单次执行中全部处理, 只输出一张合成图。 -------------------------------------------------- AI-edited local crop (B). It will be aligned, de-warped and re-composited onto the background. Crops may have different sizes (each keeps its native resolution). Natively accepts list / batch / single image — all crops are processed in ONE execution, producing one merged image.
warp_methodBOOLEANfalse形变(畸变)校正方式: · 关(Homography): 桥接H定位 + TPS非刚性畸变校正, 纯几何, 最快最稳 · 开: 在 TPS 之上叠加光流精修, 修正高频局部残差 -------------------------------------------------- Deformation-correction strategy: · OFF (Homography): bridge-H placement + TPS non-rigid correction, pure geometry · ON: adds optical-flow refinement on top of TPS
optical_flowBOOLEANfalse光流算法(仅 warp_method 开启时生效): · 关(Farneback): 最快, 纯 CPU · 开(DIS): 质量更好, 贴边缘 -------------------------------------------------- Optical-flow algorithm (only when warp_method is ON): · OFF (Farneback): fastest, CPU only · ON (DIS): better quality, edge-preserving
use_tpsBOOLEANtrueTPS 非刚性畸变校正(推荐开启): · 开: 桥接定位 + LoFTR/TPS 畸变校正 · 关: 仅桥接H定位(必要时+光流精修), 最快 -------------------------------------------------- TPS non-rigid deformation correction (recommended ON). OFF: bridge-H placement only, fastest.
second_passBOOLEANfalse二阶段精校(默认关, 仅在 TPS 路径生效): · 开: TPS 之后再做一次 LoFTR 残差精校, 慢, 少数图有改善 · 关: 跳过 -------------------------------------------------- Second-pass LoFTR residual refinement (default OFF, works only within TPS path). Slower; marginal gains.
color_matchCOMBO色彩迁移/融合策略(消除局部编辑与背景的色差): · Patch_based_color 分块LAB色差同步(推荐, 色差大/不均匀时效果好) · Edge_Weighted_Color 边缘加权色彩匹配(推荐: 保护改色物体, 纠正全图偏色) · LAB_Mean 全局均值方差匹配(轻量快速) · Laplacian Pyramid 金字塔融合(接缝最隐形, 不做色彩校正) · SeamlessClone 泊松融合(内容基本未变时消接缝; 内容大改区域慎用, 易褪色) · Alpha Soft Blend 仅羽化混合(色差已很小时用) -------------------------------------------------- Color transfer / blending strategy: · Patch_based_color: patch-wise LAB color sync (recommended for casts) · Edge_Weighted_Color: edge-aware LAB matching (protects modified areas & fixes global casts) · LAB_Mean: global mean/std matching in LAB (lightweight) · Laplacian Pyramid: multi-band blending (best seams, no color correction) · SeamlessClone: Poisson blending (seams only; avoid on heavily-edited content) · Alpha Soft Blend: feathered alpha blending only
feather_kernelINT200–256羽化半径(px): 贴图边缘柔化宽度, 兼作 Patch 色彩同步的块尺寸基准。一般 15~40; 越大过渡越柔但可能侵入更多原始内容。 -------------------------------------------------- Feather radius (px): edge-softening width of the pasted crop; also used as the patch-size basis for Patch/Boundary color sync. Typical 15~40; larger = softer transition but may eat into more original content.
merge_modeCOMBO· All to One: 所有 B 裁块按顺序贴回第一张背景图(多元素拼贴, 输出 1 张) · One to One: 背景与裁块一一对应(输出与背景数量相同的 batch)。 -------------------------------------------------- · All to One: paste all B crops sequentially onto the first background (multi-element collage, 1 output) · One to One: background-crop pairs matched one by one (outputs a batch with the same count as backgrounds)
use_gpuBOOLEANtrue使用 CUDA 加速特征匹配/光流/混合。无显卡或显存不足时可关闭。 -------------------------------------------------- Use CUDA acceleration for matching / optical flow / blending. Turn off if no GPU or VRAM is insufficient.
force_recomputeBOOLEANfalse强制清空对齐缓存并重新计算(缓存容量 4 组, LRU)。输入未变但想重跑对齐时开启。 -------------------------------------------------- Force-clear the alignment cache (LRU, 4 entries) and recompute. Enable when inputs are unchanged but you want alignment re-run.
original_crop_AoptIMAGE可选: 编辑前的局部裁块(A), 与 B 同视角同内容。提供后启用桥接对齐 B→(等比)→A→(SIFT)→BG, 对位比自动匹配更稳, 且仍执行光流畸变校正; 不提供则直接在背景上自动特征匹配。 原生支持 List / Batch / 单张输入; A 与 B 数量/尺寸不必严格一致(自动按索引配对)。 -------------------------------------------------- Optional: pre-edit local crop (A), same viewpoint/content as B. When provided, bridge alignment B→(scale)→A→(SIFT)→BG is used — more reliable placement than auto-matching, and optical-flow deformation correction still applies. Natively accepts list / batch / single image; A and B counts/sizes need not match exactly (paired by index).
split_gridoptELEMENT_TILE_GRID可选: ElementTileSplit 的 grid 信息。连接后每个 crop 的 alpha/羽化处理改为 ElementTileMerge 的方式(基于 fade_top/bottom/left/right 线性渐变 + 圆角 mask 高斯羽化, 逐 tile 加权累加再平均)。 色彩匹配、TPS、光流对齐逻辑保持不变。 -------------------------------------------------- Optional: grid from ElementTileSplit. When connected, per-tile alpha/feathering follows ElementTileMerge (fade-based linear ramp + rounded-corner gaussian feather, accumulated weighted average). Color match / TPS / optical-flow alignment remain unchanged.

Outputs (1)

NameTypeDescription
Merged_ImageIMAGE融合后的完整图像(batch) | Merged image(s) as a standard batch