Inpaint Segments
Give a tiny masked region a full 1024×1024 generation budget
- image
- mask
- mask_mapping_optional
- cut image
- cut mask
- region
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
imageandmask- 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 thecut imageoutput becomes.RGBis the normal crop to feed VAE Encode;maskgives you a mask image instead (for mask-aware encoding);RGBAkeeps 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_ratiowithconstraint_x/constraint_yat 64 is the sane default. Setmultiple_ofwith constraints of 8 if your checkpoint needs dimensions divisible by 8.batch_behavior- for multiple masks in one batch,match_ratiogives each island its own ratio,match_sizeforces one size for all.match_ratiois 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
paddingat 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
constraintstomultiple_ofwithconstraint_x/constraint_yat 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 maskandregionbatch 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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | IMAGE | — | |
| force_resize_width | INT | 10240–1048576 | — |
| force_resize_height | INT | 10240–1048576 | — |
| kind | COMBO | 3 options: mask, RGB, RGBA | |
| padding | INT | 30–1048576 | — |
| constraints | COMBO | 4 options: keep_ratio, keep_ratio_divisible, multiple_of, ignore | |
| constraint_x | INT | 642–1048576 | — |
| constraint_y | INT | 642–1048576 | — |
| min_width | INT | 00–1048576 | — |
| min_height | INT | 00–1048576 | — |
| batch_behavior | COMBO | 2 options: match_ratio, match_size | |
| mask_mapping_optionalopt | MASK_MAPPING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| cut image | IMAGE | — |
| cut mask | IMAGE | — |
| region | IMAGE | — |