Context Inpainter / Fixer
Smartly stitch an inpainted region back so the seam disappears
- original_image
- mask
- inpainted_image
- blended_image
- debug_mask
The hard part of inpainting was never getting the model to draw the new pixels. It's getting those pixels to blend back into the original without a visible seam, a color shift, or a patch that's darker than its surroundings. Context Inpainter (MEC) is the blend-back stage: it takes the original, the inpainted result, and the mask, and stitches them together with crop padding, feathered blending, color matching, and a couple of clever rescue passes.
It's node two in the pack's paint suite, and it's the piece that makes the "paint → inpaint → fix" loop actually look done.
How it works
Three inputs - original_image, mask, inpainted_image - plus the blending logic:
crop_padding(default 1.2) - extends the masked bounding box so the blend uses context around the region, not just the patch edge.blend_softness- Gaussian feather radius on the blend mask (default 8). The seam-hider.mask_expansion_blend- dilate/erode the blend mask so the feathered zone sits where you want it.enable_color_correction(default on) - Reinhard mean/std color matching between the original and inpainted regions. This is the fix for the classic "inpaint came back with a different tint" complaint.enable_lightness_rescue(default on) - lifts the CIE LAB L-channel when the inpaint comes back more than ~5% darker than the original. Inpaints run dark; this is a real fix for a real pattern.enable_differential_diffusion- uses|original - inpaint|as a soft preservation weight, keeping pixels that didn't actually change untouched and sharp. Turn it on when the inpaint is drifting regions it shouldn't touch.
Outputs: blended_image (the final composite) and debug_mask (the blend mask after expansion and blur - wire it to a preview to see what you're blending, the sampling_mask_blur_size/strength knobs tune it).
The optional face_positive_prompt/face_negative_prompt inputs parse {a|b|c} wildcards per detected mask region - but the tooltip is explicit: this node does not sample. It logs the prompts for a downstream face-inpaint/KSampler.
Where it fits
In the suite: Advanced Paint Canvas → (your inpaint node) → Context Inpainter → Tone Refiner. Standalone, it's the upgrade over a plain paste-back whenever the inpaint region is large or the lighting differs. Note it assumes the inpaint already happened - this node never runs a sampler, so if you wire it without a real inpainted_image you're just blending the original into itself.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git
pip install opencv-python>=4.7.0 scipy>=1.10.0
or ComfyUI Manager → search "CustomNodePacks", restart, confirm [MEC] Loaded .... No heavy deps. If the seam is still visible after blend_softness 8, raise mask_expansion_blend and blend_softness together - a thin feathered band over a mismatched region just moves the seam a few pixels.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| original_image | IMAGE | Original (un-inpainted) image used as the blend base. | |
| mask | MASK | Mask defining the inpainted region. | |
| inpainted_image | IMAGE | Inpainted image to blend back over the original. | |
| crop_padding | FLOAT | 1.201–2 | Multiplier extending the masked bbox so the inpaint sees more context. |
| blend_softness | FLOAT | 8.00–200 | Gaussian feather radius applied to the blend mask in pixels. |
| mask_expansion_blend | INT | 0-100–100 | Per-blend dilate (positive) / erode (negative) of the blend mask in pixels. |
| enable_color_correction | BOOLEAN | true | Reinhard mean/std color match between original and inpainted regions. |
| enable_lightness_rescue | BOOLEAN | true | Lift CIE LAB L-channel of the inpaint when it is more than ~5% darker. |
| enable_differential_diffusion | BOOLEAN | false | Use |orig - inpaint| as a soft preservation weight to keep unchanged pixels. |
| sampling_mask_blur_size | INT | 210–201 | Kernel size (odd) for the additional blur on the output debug mask. |
| sampling_mask_blur_strength | FLOAT | 1.000–1 | Blend factor for the sampling mask blur applied to debug_mask. |
| face_positive_promptopt | STRING | Optional region-attached positive prompt; parsed for `{a|b|c}` wildcards per detected mask region and logged. Does NOT sample here -- pair with a FaceInpaint/KSampler downstream. | |
| face_negative_promptopt | STRING | Same as face_positive_prompt but for negatives. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| blended_image | IMAGE | Final composited image with the inpainted region blended back into the original. |
| debug_mask | MASK | Debug mask used for the blend (after expansion and blur). |