Nodes/ComfyUI_Element_high/EH - Merge Back (V5+Mask)
ComfyUI Node

EH - Merge Back (V5+Mask)

The merge node the README will try to gaslight you about

By heyzne·Created 3 months ago·Updated 3 months ago· 0
EH - Merge Back (V5+Mask)
  • original_image
  • edited_crop
  • original_crop
  • result
  • blend_mask
aligntrue
edge_pixels12
edge_awaretrue
color_match_modemean_shift
color_match_strength0.50
blend_modeedge_aware

This is the node this pack exists for. Crop a region, regenerate just the crop - a jacket swap, a face touch-up - and EH - Merge Back (V5+Mask) puts the edit back into the original frame without the seam, the color shift, or the skin that comes back looking like a different person's. It's the "stitch" half of the crop-edit-stitch pattern, and it's the reason anyone installs Element_high at all.

Now the part you need to hear before you build anything: the README will try to gaslight you. Its whole pitch is "connect your inpaint mask to the mask input" - and there is no mask input. Not in the schema, not in the shipped code. The name says "Mask" because the node generates a mask for you (an edge-aware blend mask), not because it takes one from you. If you go hunting for a mask socket to wire your hand-painted region into, you'll come up empty and assume you're doing something wrong. You're not.

The two required inputs are original_image (the full, untouched frame) and edited_crop (the region you regenerated). Everything else is optional. How it actually works, in order:

  • Position. Feed original_crop (the untouched crop you made before editing) and it locates that crop inside the original with template matching (OpenCV matchTemplate, 0.7 confidence). Leave it disconnected and the edited crop is simply centered - fine when the edit is the same size as the frame, wrong when it isn't. This is the input beginners skip, then wonder why the merge landed off-center.
  • Alignment. align (on by default, but only does anything when original_crop is connected) measures the subpixel shift between the original crop and the edited one via phase correlation (cv2.phaseCorrelate) and warps the edit to match. The README calls this "TPS deformation alignment"; the code is a global affine shift. It fixes drift, not pose changes - don't expect it to un-bend someone's arm.
  • Color. color_match_mode (default mean_shift) shifts each channel's mean toward the original crop's mean, scaled by color_match_strength (default 0.5). Deterministic, instant, and the right tool - this is the "make the patch agree with its neighbors" move from the post-processing playbook. One quirk: histogram mode currently runs the same mean-shift code, so don't expect real histogram matching if you select it.
  • The blend mask. With blend_mode on edge_aware (default) and edge_aware toggled on, it builds a feathered mask that blends fully in the middle of the crop and backs off at the borders - and it actively detects skin-toned and edge pixels (an HSV skin range plus Canny edges) and lowers the blend weight there, so the original skin shows through instead of being replaced by the edit's. edge_pixels (default 12) sets the feather width: raise it toward 30 when edges look hard, drop it toward 2-3 for a sharp replacement.
  • The blend. Five modes. edge_aware and alpha are direct alpha blends with that mask (alpha skips the skin detection). mixed_clone and normal_clone are OpenCV seamlessClone (Poisson-style, MIXED_CLONE and NORMAL_CLONE). guided_filter alpha-blends then bilateral-filters the seam smooth. When edges still show, mixed_clone is the one to try first.

Outputs: result (the merged frame) and blend_mask - a MASK of exactly where it blended, which is also your debugging view of "what did this node actually change."

Troubleshooting, the short version: seams → raise edge_pixels or switch to mixed_clone; skin smearing at the boundary → make sure edge_aware is on; merge landing off-center → you forgot to feed original_crop; and if you followed the README's install URL and got a 404, use the heyzne repo below instead of the dead supElement one.

cd ComfyUI/custom_nodes
git clone https://github.com/heyzne/ComfyUI_Element_high

Or search ComfyUI_Element_high in ComfyUI Manager. No models to download, no pip deps beyond ComfyUI defaults - everything is CPU-side OpenCV and numpy.

Honest verdict: for crop-inpaint-merge, the well-trodden road is lquesada's Inpaint CropAndStitch - battle-tested, huge community, and it structurally guarantees unmasked pixels are untouched. This is the lean, unproven alternative: same idea, fewer nodes, alignment and color matching baked in, but a tiny install base, a README that hasn't caught up to its own code, and a name that promises a mask input it doesn't have. Great for experimenting with auto-aligned merges. Don't build a production batch on week-one software.

CategoryElementHigh

Inputs (9)

NameTypeDefaultDescription
original_imageIMAGE
edited_cropIMAGE
original_cropoptIMAGE
alignoptBOOLEANtrue
edge_pixelsoptINT120–100
edge_awareoptBOOLEANtrue
color_match_modeoptCOMBOmean_shift3 options: none, mean_shift, histogram
color_match_strengthoptFLOAT0.500–1
blend_modeoptCOMBOedge_aware5 options: edge_aware, mixed_clone, normal_clone, guided_filter, alpha

Outputs (2)

NameTypeDescription
resultIMAGE
blend_maskMASK