Inpaint Mask Prepare
Inpaint Mask Prepare
- mask
- reference_image
- inpaint_mask
- stitch_blend_mask
- debug_preview
- info
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) withmin_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) orslight_feather(softer transition at the boundary).stitch_edge_mode-gaussianoredge_awarefor the compositing mask. Edge-aware needs areference_imagewired 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 foredge_awarestitch mode.inpaint_maskout → your sampler's mask input.stitch_blend_maskout → 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_holeshandles 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_smoothand raisetemporal_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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | Raw input mask (B,H,W) | |
| fill_holes | BOOLEAN | true | Fill interior holes in the mask |
| remove_small_regions | BOOLEAN | true | Remove small disconnected blobs |
| min_region_area | INT | 1000–100000 | Minimum region area in pixels to keep |
| grow_pixels | INT | 40–256 | Dilate mask by this many pixels |
| inpaint_edge_mode | COMBO | hard_binary | Edge style for inpaint mask: hard_binary or slight_feather |
| stitch_edge_mode | COMBO | gaussian | Edge style for stitch blend mask: gaussian or edge_aware |
| stitch_feather_radius | INT | 161–128 | Feather radius for the stitch blend mask |
| temporal_smooth | BOOLEAN | false | Apply Gaussian temporal smoothing along batch dimension (for video) |
| temporal_sigma | FLOAT | 1.50.1–10 | Temporal Gaussian sigma in frames |
| reference_imageopt | IMAGE | Reference image for edge-aware stitch blend mask (required for edge_aware mode) |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| inpaint_mask | MASK | — |
| stitch_blend_mask | MASK | — |
| debug_preview | IMAGE | — |
| info | STRING | — |