ComfyUI Node Runs on cloud

Inpaint

OpenCV inpainting — not diffusion, and that's the point — Inpaint

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
Inpaint
  • img
  • mask
  • IMAGE
radius3
flagTELEA

Before you get excited: this is not the diffusion inpainting you're thinking of. The Inpaint node is OpenCV's classic image inpainting - it fills the masked region by smearing surrounding pixels in, not by generating anything. That's not a limitation, it's the entire reason to use it.

ComfyUI's inpainting discussion is dominated by the diffusion kind: mask a region, regenerate it with the model, control it with denoise. OpenCV inpainting is a different tool for a different job. It's the "content-aware fill"-ish approach for small defects - sensor dust, scratches, power lines, watermarks, a stray artifact. You feed it an image and a mask of what to remove, and it reconstructs the area from the neighborhood using one of two classical algorithms, Telea or Navier-Stokes. It's instant (no sampler, no VRAM bake), deterministic, and it leaves everything outside the mask bit-for-bit untouched. The category in the menu is even "C.Photography" - this is a retouching node.

There's also a sneaky secondary use: pre-filling the mask region before diffusion inpainting. Diffusion models inpaint better when the masked area already contains plausible context, and an OpenCV fill is a cheap way to prime it.

How it works

The implementation is a straight passthrough to OpenCV:

img  = tensor2opencv(img)
mask = tensor2opencv(mask, 1)
dst  = cv.inpaint(img, mask, radius, method)

The mask is treated as a single-channel grayscale, and like all of OpenCV, non-zero (white) pixels mark the area to fill - make sure you didn't invert it, because inverting it fills the wrong half of the image. radius is the neighborhood the algorithm samples; flag picks between TELEA (default) and NS (Navier-Stokes).

Inputs and outputs

  • img - the IMAGE to retouch.
  • mask - an IMAGE (grayscale) where white = area to inpaint.
  • radius - INT, default 3, minimum 0. Bigger radius = smoother fill but more blur bleed; for a small scratch, 3-8 is typical.
  • flag - enum: "TELEA" (default) or "NS". Telea is faster and fine for most cleanup; NS (Navier-Stokes) sometimes tracks structure better on larger fills.
  • Output: one IMAGE, same size as the input.

Install

Ships in bmad4ever/comfyui_bmad_nodes. Via ComfyUI Manager, search "comfyui_bmad_nodes" ("Bmad Nodes"), install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt

Restart ComfyUI after. Requires opencv-python from the requirements; no model files.

Common issues

The big one is expectation-setting: people drop a large region into it and wonder why the fill looks smeary. OpenCV inpainting is for small defects; the larger the masked area, the more it looks like a blurry smear, because it's interpolating pixels, not hallucinating detail. For big regions you want diffusion inpainting. Second classic gotcha: the mask polarity (white fills, black keeps). And finally - if the mask and image don't match in size, conversions can silently go sideways, so keep them the same dimensions. Use it for the small stuff and it's genuinely handy; use it for a face swap and you'll be disappointed.

CategoryBmad/CV/C.Photography

Inputs (4)

NameTypeDefaultDescription
imgIMAGE
maskIMAGE
radiusINT3
flagCOMBOTELEA2 options: TELEA, NS

Outputs (1)

NameTypeDescription
IMAGEIMAGE