ComfyUI_Element_high
Mask-guided precision merge plugin for ComfyUI. Fixes skin misalignment and edge artifacts in crop-and-inpaint workflows by only replacing pixels inside the mask region.
Nodes (4)
A pair of eyes on whether your crop drifted
Point a mask at it and it crops the region for you
The boring crop node that also hands you the receipt
The merge node the README will try to gaslight you about
ComfyUI_Element_high
Mask-guided precision merge plugin for ComfyUI.
Fixes skin misalignment and edge artifacts in crop-and-inpaint workflows by only replacing pixels inside the mask region.
Problem Solved
When using crop-inpaint-merge workflows (e.g., clothing replacement), the original plugin had these issues:
- Skin misalignment: Edited crop includes skin that doesn't perfectly align with original
- Edge artifacts: Visible seams at crop boundaries
- Color bleeding: Edited content bleeds into surrounding skin
Solution: Use an inpaint mask to control exactly which pixels get replaced. Skin pixels outside the mask are completely untouched.
Installation
Method 1: ComfyUI Manager (Recommended)
Search for ComfyUI_Element_high in ComfyUI Manager and install.
Method 2: Manual
cd ComfyUI/custom_nodes
git clone https://github.com/supElement/ComfyUI_Element_high.git
Method 3: Zip
Download the release zip and extract to ComfyUI/custom_nodes/ComfyUI_Element_high/.
Requirements
No additional packages required beyond ComfyUI defaults:
- torch
- numpy
- opencv-python
- Pillow
Nodes
| Node | Description | |------|-------------| | EH - Crop Image | Crop image by coordinates | | EH - Crop From Mask | Auto-crop from mask bounding box | | EH - Merge Back (Mask Guided) | Merge edited crop back with mask control | | EH - Check Alignment | Detect offset between original and edited |
Workflow
Clothing Replacement (Recommended)
[Load Image: Original] ──┬──> [Inpaint Node] ──> [Edited Crop]
│ │
[Load Image: Mask] ──────┤ │
│ ▼
└──> [EH_CropFromMask] ──> [EH_MergeBack] ──> [Save Image]
│ ▲
└──> crop_box ───────┤
│
[Load Image: Original Crop] ──────────────────────────┤
│
[Mask (from inpaint)] ────────────────────────────────┘
Key Parameters (EH_MergeBack)
| Parameter | Default | Description |
|-----------|---------|-------------|
| mask | None | CRITICAL: Connect inpaint mask here. Only masked pixels are replaced. |
| align | true | Enable phase-correlation alignment correction |
| auto_mask | true | Auto-generate mask from pixel differences (fallback if no mask) |
| mask_threshold | 15 | Pixel difference threshold for auto-mask (higher = less replacement) |
| edge_feather | 6 | Feather pixels at mask boundary (0 = hard edge) |
| color_match | true | Match colors in masked region to original |
| color_strength | 0.5 | Color match intensity |
| blend_mode | masked | masked / poisson / alpha |
Fixing Skin Misalignment
The key is the mask input.
- Create an inpaint mask that covers only the clothing area, not the skin
- Connect this mask to
EH_MergeBack.mask - Skin pixels outside the mask will be completely untouched
- Only clothing pixels inside the mask get replaced
Recommended settings for clothing replacement:
mask: [your inpaint mask]
align: true
auto_mask: true (as fallback)
edge_feather: 6
color_match: true
color_strength: 0.5
blend_mode: masked
Blend Modes
| Mode | Use Case | |------|----------| | masked | Default. Alpha blend using mask. Best for most cases. | | poisson | Poisson blending (MIXED_CLONE). Best for skin edges. | | alpha | Simple alpha blend. Fastest. |
Why Skin Misalignment Happens
- You crop a region that includes both clothing and skin
- AI inpaint changes the clothing but may slightly shift/change the skin
- When merging back, the shifted skin creates a visible seam
Fix: The mask input ensures only the clothing (masked) pixels are replaced. Skin pixels (mask=0) remain exactly as in the original image.
Tips
- Always use a mask: Connect your inpaint mask to
EH_MergeBack.maskfor best results - Mask should cover only what you want to change: Don't include skin in the mask
- Edge feather: Increase to 10-15 if you see hard edges, decrease to 0-3 for sharp replacement
- Color match: Disable if the edited colors look correct already
Changelog
v5.0
- TPS deformation alignment
- Edge-aware blending
- Skin edge detection
License
MIT License - see LICENSE file.
Credits
Based on the concept from ComfyUI_Element_easy by supElement. Rewritten with mask-guided precision merge to fix skin misalignment issues.