Nodes/ComfyUI-CustomNodePacks/Inpaint Mask Prepare
ComfyUI Node

Inpaint Mask Prepare

Inpaint Mask Prepare

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
Inpaint Mask Prepare
  • mask
  • reference_image
  • inpaint_mask
  • stitch_blend_mask
  • debug_preview
  • info
fill_holestrue
remove_small_regionstrue
min_region_area100
grow_pixels4
inpaint_edge_modehard_binary
stitch_edge_modegaussian
stitch_feather_radius16
temporal_smoothfalse
temporal_sigma1.5

Inpaint Mask Prepare is the cleanup node that sits between "your mask exists" and "your inpaint run" - and it's the difference between a clean result and a mask-shaped disaster. Segmentation models hand you messy masks: pinholes where the model waffled, tiny disconnected blobs of noise, edges that don't quite cover the subject. Run that straight into an inpaint sampler and you'll get random detail painted into the pinholes and the blobs. This node cleans all of it up and, crucially, produces two different masks for the two different jobs: one for the inpaint model, one for compositing back.

It's part of the C2C/Inpaint suite in ComfyUI-CustomNodePacks, the ~72-node pack from Code2Collapse (Likhith-24, active on r/comfyui).

How it works

The pipeline is: fill holes → remove small blobs → dilate → emit dual masks.

  • fill_holes (default true) - fills fully-enclosed regions inside the mask. That's the pinhole fix.
  • remove_small_regions (default true) with min_region_area (default 100px) - kills disconnected specks. Without this, a 3-pixel glitch becomes a 3-pixel blob of hallucinated detail in your output.
  • grow_pixels (default 4) - dilates the mask so the inpaint covers the real edge of the subject instead of stopping a pixel short.
  • inpaint_edge_mode - hard_binary (what the model sees) or slight_feather (softer transition at the boundary).
  • stitch_edge_mode - gaussian or edge_aware for the compositing mask. Edge-aware needs a reference_image wired in - it feathers along real image edges instead of a plain blur, which is what makes a seam invisible on textured surfaces.

The video-friendly extra: temporal_smooth with temporal_sigma applies Gaussian smoothing along the batch dimension, so a jittery per-frame mask doesn't flicker through your video output. This is the setting that makes a one-off mask tool usable on a 200-frame sequence.

Outputs: inpaint_mask (feed to the sampler), stitch_blend_mask (feed to the stitch/composite side), debug_preview (a visual to check before you waste a run), and info (a string summary).

The inputs and outputs that matter

  • mask - the raw mask in (B,H,W).
  • fill_holes / remove_small_regions - leave both on; turn off only if your mask's structure depends on small details.
  • grow_pixels - 2-8 is the realistic band. More coverage, less precision.
  • reference_image (optional) - required for edge_aware stitch mode.
  • inpaint_mask out → your sampler's mask input.
  • stitch_blend_mask out → the stitch/composite node.

Installing it

Ships in ComfyUI-CustomNodePacks. ComfyUI Manager → search "CustomNodePacks", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

Pure torch/opencv ops - the pack's standard deps (opencv-python>=4.7.0, scipy>=1.10.0) cover it; install just what's missing (not the full requirements.txt, which can clobber ComfyUI's torch). No models. Restart ComfyUI.

Common issues

  • Edge-aware mode errors or looks wrong - you forgot the reference_image. That mode is impossible without it; wire the image and it works.
  • Mask still has holes after fill - fill_holes handles fully-enclosed regions only; a mask that's open to the edge can't be "filled." That's a segmentation problem, not a cleanup one - re-run your segmenter.
  • Video flickers frame to frame - turn on temporal_smooth and raise temporal_sigma (1.5-3). Smoothing across frames trades a bit of per-frame precision for stability, which is what video wants.

The honest take: this node is the "read your mask before you spend a GPU hour on it" discipline made into a graph node. Skip it and you'll learn why masks need cleaning the slow way - through a run of speckled inpaint output.

CategoryC2C/Inpaint

Inputs (11)

NameTypeDefaultDescription
maskMASKRaw input mask (B,H,W)
fill_holesBOOLEANtrueFill interior holes in the mask
remove_small_regionsBOOLEANtrueRemove small disconnected blobs
min_region_areaINT1000–100000Minimum region area in pixels to keep
grow_pixelsINT40–256Dilate mask by this many pixels
inpaint_edge_modeCOMBOhard_binaryEdge style for inpaint mask: hard_binary or slight_feather
stitch_edge_modeCOMBOgaussianEdge style for stitch blend mask: gaussian or edge_aware
stitch_feather_radiusINT161–128Feather radius for the stitch blend mask
temporal_smoothBOOLEANfalseApply Gaussian temporal smoothing along batch dimension (for video)
temporal_sigmaFLOAT1.50.1–10Temporal Gaussian sigma in frames
reference_imageoptIMAGEReference image for edge-aware stitch blend mask (required for edge_aware mode)

Outputs (4)

NameTypeDescription
inpaint_maskMASK
stitch_blend_maskMASK
debug_previewIMAGE
infoSTRING