Nodes/ComfyI2I/Inpaint Segments
ComfyUI Node

Inpaint Segments

Give a tiny masked region a full 1024×1024 generation budget

By ManglerFTW·Created 3 years ago·Updated 2 years ago· 181
Inpaint Segments
  • image
  • mask
  • mask_mapping_optional
  • cut image
  • cut mask
  • region
force_resize_width1024
force_resize_height1024
kind
padding3
constraints
constraint_x64
constraint_y64
min_width0
min_height0
batch_behavior

Inpaint Segments is the crop half of ComfyI2I's image-to-image loop, and it exists to fix the oldest inpainting problem: a 64-pixel eye in a 1024×1024 image gets almost no sampling budget if you run it full-frame. This node takes your image plus its mask(s), finds the bounding box of every mask island, pads it out, and resizes the crop to 1024×1024 (or whatever you set) before it ever reaches the sampler. A tiny region then gets a full-resolution generation budget - the "only masked" trick that whole-frame edit models cannot do at any setting.

How it works

The node computes a bounding box per mask via masks_to_boxes, expands it by padding, then applies the sizing rules you give it. Output is three things: cut image (the crop, upscaled), cut mask (the same crop of the mask, so it lines up exactly), and region (a full-resolution layout of the boxes - this is what tells the paste stage where to put everything back).

The flow is Mask Ops (or your own mask) → Inpaint Segments → VAE Encode → KSampler → VAE Decode → Combine and Paste. Note what isn't in that chain: the unmasked image. It never goes through the VAE at all, so the untouched pixels come back bit-identical. That's the design that later became the community-standard "crop and stitch" pattern - this node is the older, self-contained ancestor of it.

The inputs that actually matter

  • image and mask - your source and its masks. The mask is an IMAGE input, so it's happy with a mask rendered as a black-and-white image.
  • force_resize_width / force_resize_height - the generation size, 1024×1024 by default. That's the whole point: pick your model's happy resolution here.
  • kind - what the cut image output becomes. RGB is the normal crop to feed VAE Encode; mask gives you a mask image instead (for mask-aware encoding); RGBA keeps alpha.
  • padding - pixels added around each bounding box. Default is 3, which is tiny. For small detail fixes you want 32–64px so the sampler sees real context around the edit; too little padding and the model guesses blind.
  • constraints - how the crop size is normalized. keep_ratio with constraint_x/constraint_y at 64 is the sane default. Set multiple_of with constraints of 8 if your checkpoint needs dimensions divisible by 8.
  • batch_behavior - for multiple masks in one batch, match_ratio gives each island its own ratio, match_size forces one size for all. match_ratio is what you want unless your masks are wildly different shapes.

Install

The pack ships with ComfyUI Manager - search "ComfyI2I" (or ManglerFTW/ComfyI2I). Manual route:

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

Restart ComfyUI; the nodes land under the I2I category. Heads up on that requirements file: it lists tensorflow and scikit-image that the code never imports - you're downloading hundreds of MB for nothing. The actual machinery here just needs numpy, torch, torchvision and opencv. On Linux or non-admin Windows, ComfyUI also needs write access to custom_nodes/ComfyI2I/ComfyI2I.py (the pack copies its JS into web/extensions on startup).

Common issues

  • Blurry or smeared inpaint. You left padding at 3. The sampler has no context to work with. Crank it to 32–64 and re-run.
  • "The model expects dimensions divisible by 8" errors downstream. Switch constraints to multiple_of with constraint_x/constraint_y at 8 (or 64 for the default case) so crops come out divisible.
  • Batch misalignment when pasting back. Keep every mask island flowing through the same Inpaint Segments instance and pair the outputs - the cut image, cut mask and region batch orders have to stay in lockstep or the paste stage throws "no entry for mask index i".

The pack itself has been quiet since late 2023, so don't expect updates. But the crop-inpaint-paste mechanism it ships is simple and robust enough that it still runs today - and it's the cleanest way to get the one thing instruction-editing models still can't give you: exact detail at full resolution, with everything outside the mask left perfectly alone.

CategoryI2I

Inputs (13)

NameTypeDefaultDescription
imageIMAGE
maskIMAGE
force_resize_widthINT10240–1048576
force_resize_heightINT10240–1048576
kindCOMBO3 options: mask, RGB, RGBA
paddingINT30–1048576
constraintsCOMBO4 options: keep_ratio, keep_ratio_divisible, multiple_of, ignore
constraint_xINT642–1048576
constraint_yINT642–1048576
min_widthINT00–1048576
min_heightINT00–1048576
batch_behaviorCOMBO2 options: match_ratio, match_size
mask_mapping_optionaloptMASK_MAPPING

Outputs (3)

NameTypeDescription
cut imageIMAGE
cut maskIMAGE
regionIMAGE