Nodes/ComfyUI-NKD-Basic-Tools/😺NKD Inpaint Crop
ComfyUI Node

😺NKD Inpaint Crop

Detail one region without re-rendering the rest — crop to the mask's budget

By Nekodificador·Created about a month ago·Updated 3 days ago· 71
😺NKD Inpaint Crop
  • image
  • mask
  • model
  • vae
  • model
  • image
  • mask
  • latent
  • crop_data
â—„invert_maskfalseâ–º
â—„fill_holestrueâ–º
â—„mask_expand20â–º
â—„mask_blur10â–º
â—„inpaint_blend1.00â–º
â—„padding50â–º
â—„resize_modeAutomaticâ–º
â—„megapixels1.00â–º
â—„longest_side1024â–º
â—„min_resolution768â–º
â—„max_resolution2048â–º
â—„separate_regionsfalseâ–º
â—„region_min_area0.10â–º
â—„max_regions8â–º
â—„region_orderLargest Firstâ–º

The best inpainting in ComfyUI doesn't render the whole image - it cuts out the part you care about, renders that at the resolution the model likes, and pastes it back. The mask-anywhere pattern (Inpaint Crop → model → Inpaint Stitch) became the community standard for a simple reason: the unmasked pixels never touch the VAE, so they stay bit-identical while a 64px eye gets a full 1024px of generation budget. 😺NKD Inpaint Crop is the first half of that pattern, and it's the friendliest version of it I've seen.

Crop takes your image and mask and hands back everything your sampling pipeline needs - prepared, resampled, and ready. What makes it more than a crop:

  • Mask cleanup built in. Invert, fill holes, expand (default 20px), and soften (default 10px) all happen here instead of a chain of four nodes before it. The same softness is used when compositing back, so what you tune is what you get.
  • resize_mode decides the working resolution. Automatic keeps the original resolution and only rescales when the crop falls outside the min/max limits; Megapixels gives a fixed budget (1.0 ≈ 1024×1024); Longest Side an exact size. min_resolution (768) and max_resolution (2048) are the fences for Automatic.
  • Connect model and vae (both optional) and Crop hands back a prepared model and a ready-to-sample latent, so nothing sits between it and your sampler. The model output applies the soft-mask denoise schedule inline - the same behavior as core's DifferentialDiffusion - so the regenerated area follows the mask softness for a cleaner inpaint, with no extra nodes.
  • separate_regions - detail several areas in one go. Each separate blob of the mask gets its own crop, the sampler runs once per area automatically, and 😺NKD Inpaint Stitch composites them all back in one pass. Filter by region_min_area, cap with max_regions, order with region_order.

Outputs

model, image, mask, and latent (all list-typed, one entry per region) - plus crop_data, which you feed to Inpaint Stitch so it knows where everything goes back. The node previews the mask and crop region on itself, and its play button runs just that branch, so you can frame the crop without running the whole graph.

Install and gotchas

Install via ComfyUI Manager (search ComfyUI-NKD-Basic-Tools) or:

cd ComfyUI/custom_nodes
git clone https://github.com/Nekodificador/ComfyUI-NKD-Basic-Tools

Restart after. Pack dependencies are onnxruntime and huggingface_hub; neither is needed here. The community's standing advice applies: detail at native resolution first, upscale after; lock your seed while tuning; and composite after every inpainting pass (this node pair makes that structural rather than a discipline). For a small fix, don't overdo padding - 32–64px of context is the classic range, and more just spreads the generation budget thinner.

Category😺NKD Nodes/Basic

Inputs (19)

NameTypeDefaultDescription
imageIMAGE—
maskMASK—
invert_maskBOOLEANfalseInvert the mask before processing.
fill_holesBOOLEANtrueFill enclosed gaps in the mask so each area becomes a solid shape.
mask_expandINT200–512Grow the mask outward by this many pixels.
mask_blurINT100–256Soften the mask edge by this many pixels. The same softness is used when compositing back.
inpaint_blendFLOAT1.000–1How sharp the transition is between the regenerated area and the original image. Lower values fade the two together more gently. Only used when model is connected.
paddingINT500–2048How much surrounding image to include around the mask, in pixels. More context helps the edit blend with the scene.
resize_modeCOMBOAutomaticHow the crop's working resolution is chosen. Automatic: keeps the original resolution and only rescales when the crop is too small or too big. Megapixels: fixed budget. Longest Side: exact size.
megapixelsFLOAT1.000–16Working resolution for the crop, in megapixels (1.0 ≈ 1024×1024). 0 = keep the original resolution untouched.
longest_sideINT102416–8192Exact size of the crop's longest side, in pixels.
min_resolutionINT76864–4096If the crop is smaller than this, it is scaled up to reach it.
max_resolutionINT204864–16384If the crop is larger than this, it is scaled down to fit. Crops in between keep their original resolution.
separate_regionsBOOLEANfalseDetail several areas in one go: each separate area of the mask gets its own crop, your sampler runs once per area automatically, and Stitch puts them all back.
region_min_areaFLOAT0.100–100Ignore areas smaller than this percentage of the image.
max_regionsINT81–64Process at most this many areas.
region_orderCOMBOLargest FirstOrder in which the areas are processed.
modeloptMODELOptional. Connect your model and use the model output: the regenerated area will follow the mask softness for a cleaner inpaint, with no extra nodes.
vaeoptVAEOptional. Connect your VAE and the latent output comes out ready to plug straight into the sampler.

Outputs (5)

NameTypeDescription
modelMODELModel prepared for masked inpainting. Requires model.
imageIMAGEThe cropped region(s), at working resolution.
maskMASKMask for each crop.
latentLATENTReady-to-sample crop(s). Requires vae.
crop_dataNKD_CROPDATAConnect to 😺NKD Inpaint Stitch.