Nodes/opencv-comfyui/OpenCV inpaint_0
ComfyUI Node

OpenCV inpaint_0

The fast, deterministic way to remove text, dust, and watermarks

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV inpaint_0
  • src
  • inpaintMask
  • dst
  • nparray
inpaintRadius
flags

inpaint_0 removes small regions from an image and fills them in with what's around them - using an old, deterministic OpenCV algorithm, not a model. Give it an image and a mask marking the bad pixels, and it reconstructs the masked area by propagating nearby texture and structure inward. This is the classical computer-vision inpainting that long predates diffusion, and it's the tool for a specific set of jobs: erasing text overlays, watermarks, date stamps, sensor dust, scratches, or stray specks - small defects on flat or textured backgrounds where the surrounding pixels tell you everything you need to know.

It is not what people usually mean by "inpainting" in ComfyUI. The inpainting.md docs here are about masked diffusion re-generation - Flux Fill, SDXL inpaint - where a model invents new detail. This node invents nothing; it interpolates. The honest split: a diffusion inpaint will correctly regenerate a missing eye or a complex object; cv2.inpaint will smear. But for a watermark or a scratch, cv2.inpaint is instant, deterministic, uses no VRAM, and can't drift into "the model reimagined my image" territory. The KB's post-processing doc makes the general point well: for a deterministic pixel job, reach for the millisecond operation, not a diffusion pass. This is exactly that case.

How it works. Two algorithms, selected by the flags input: 1 (INPAINT_TELEA) uses a fast marching method that fills from the boundary inward, prioritizing nearby known pixels; 0 (INPAINT_NS) is Navier-Stokes based, propagating edges as fluid dynamics would. Telea (1) is the usual first choice - faster and generally smoother for small regions.

Inputs that matter:

  • src (NPARRAY) - the image to repair. BGR uint8, as always in this pack.
  • inpaintMask (NPARRAY) - the region to fill. White (255) pixels mark what gets inpainted, black keeps everything else. This must be a single-channel NPARRAY, which is where people stumble: ComfyUI's MASK outputs aren't directly compatible, so get your mask into nparray form and, if needed, convert with cvtColor (6 = BGR2GRAY) to match what OpenCV expects.
  • inpaintRadius (FLOAT) - the radius OpenCV considers when sampling. Default in OpenCV is 3; small text needs ~2–4, bigger watermarks want more. Too small and the fill won't reach; too big and it gets mushy.
  • flags (INT) - 1 (Telea) or 0 (Navier-Stokes).

dst is the optional out-parameter - leave it unwired, take the nparray output.

Output. One nparray (NPARRAY) - the repaired image. Convert back to a ComfyUI IMAGE with Nparrays2Image.

Installing. ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Restart ComfyUI; it's under image/OpenCV.

Where people get burned. The mask type is the classic one - a Comfy MASK tensor wired straight in will fail with an assertion error; convert it to a single-channel NPARRAY first. The README's grayscale assertion (img.type() == CV_8UC1) is the tell. Also remember batch-of-one for any image entering the pack, and that both image and mask must be same-size uint8 arrays. And set expectations: on complex textures or large regions, the result will look smeared - that's the algorithm, not a bug. For big regenerations, use a diffusion inpaint; for removing a watermark, this is the right node, and inpaint_1 is its identical twin (same generated code, pick either).

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
srcNPARRAY
inpaintMaskNPARRAY
inpaintRadiusFLOAT
flagsINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY