Nodes/ComfyUI-CustomNodePacks/Context Inpainter / Fixer
ComfyUI Node

Context Inpainter / Fixer

Smartly stitch an inpainted region back so the seam disappears

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
Context Inpainter / Fixer
  • original_image
  • mask
  • inpainted_image
  • blended_image
  • debug_mask
crop_padding1.20
blend_softness8.0
mask_expansion_blend0
enable_color_correctiontrue
enable_lightness_rescuetrue
enable_differential_diffusionfalse
sampling_mask_blur_size21
sampling_mask_blur_strength1.00
face_positive_prompt
face_negative_prompt

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.

CategoryC2C/Paint

Inputs (13)

NameTypeDefaultDescription
original_imageIMAGEOriginal (un-inpainted) image used as the blend base.
maskMASKMask defining the inpainted region.
inpainted_imageIMAGEInpainted image to blend back over the original.
crop_paddingFLOAT1.201–2Multiplier extending the masked bbox so the inpaint sees more context.
blend_softnessFLOAT8.00–200Gaussian feather radius applied to the blend mask in pixels.
mask_expansion_blendINT0-100–100Per-blend dilate (positive) / erode (negative) of the blend mask in pixels.
enable_color_correctionBOOLEANtrueReinhard mean/std color match between original and inpainted regions.
enable_lightness_rescueBOOLEANtrueLift CIE LAB L-channel of the inpaint when it is more than ~5% darker.
enable_differential_diffusionBOOLEANfalseUse |orig - inpaint| as a soft preservation weight to keep unchanged pixels.
sampling_mask_blur_sizeINT210–201Kernel size (odd) for the additional blur on the output debug mask.
sampling_mask_blur_strengthFLOAT1.000–1Blend factor for the sampling mask blur applied to debug_mask.
face_positive_promptoptSTRINGOptional 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_promptoptSTRINGSame as face_positive_prompt but for negatives.

Outputs (2)

NameTypeDescription
blended_imageIMAGEFinal composited image with the inpainted region blended back into the original.
debug_maskMASKDebug mask used for the blend (after expansion and blur).