Nodes/AusBoss/Crop For Inpaint πŸ†Ž
ComfyUI Node

Crop For Inpaint πŸ†Ž

Inpaint at full resolution without touching the rest of the frame

By ausbossΒ·Created 2 months agoΒ·Updated 4 days agoΒ· 2
Crop For Inpaint πŸ†Ž
  • image
  • mask
  • image
  • mask
  • stitcher
β—„context_factor1.20β–Ί
β—„blend_pixels16β–Ί
β—„output_multiple8β–Ί
β—„target_width0β–Ί
β—„target_height0β–Ί
β—„mask_grow0β–Ί
β—„mask_blur0.0β–Ί
β—„invert_maskfalseβ–Ί
β—„context_pixels0β–Ί
β—„target_megapixels0.00β–Ί
β—„rescale_algorithmbilinearβ–Ί
β—„extend_left0β–Ί
β—„extend_right0β–Ί
β—„extend_up0β–Ί
β—„extend_down0β–Ί

Here's the dirty secret of whole-frame inpainting: you send the entire image through the sampler, and even the "untouched" pixels get degraded by the VAE encode/decode round trip. The crop-and-stitch pattern exists to fix exactly that - crop around the mask, inpaint only that region, paste it back so every pixel outside the fix is byte-for-byte identical. It's the pattern the knowledge base calls the structural answer to the oldest rule in inpainting, and Crop For Inpaint πŸ†Ž is the crop half of it, paired with Stitch Inpaint πŸ†Ž.

The payoff is the thing everyone actually wants from inpainting: a 64px eye gets 1024px of generation budget because the crop renders at native resolution, and the rest of the image never passes through a model at all.

What it does

You feed it the image and a mask (white = what to repaint). It grows the mask's bounding box outward by context_factor (default 1.2) so the inpainter sees surrounding context, plus optional flat context_pixels if you want guaranteed padding. It then crops that region and emits:

  • image - the crop, sized for the sampler.
  • mask - a hard-edged sampling mask matching the crop. By design it is never feathered; feathering lives separately in the stitcher's blend mask, used only at paste time.
  • stitcher - an AUSBOSS_STITCHER that carries the canvas, the rectangle, the blend mask, and the scale to Stitch Inpaint.

The stitcher is the clever bit: it broadcasts across a video batch, so one crop serves a whole clip. Crop once, run the inpainter over every frame, stitch once.

The inputs that matter

  • blend_pixels (default 16) - feather width for pasting back. 0 pastes hard. This is not the sampling mask; don't confuse the two.
  • output_multiple (default 8) - rounds crop and target up to a multiple so samplers accept them.
  • target_width / target_height / target_megapixels - rescale the crop to a sampler-friendly area. 1.0 megapixel suits SDXL-class models; 0 keeps native size. Explicit target width/height overrides the megapixel target.
  • mask_grow - dilates (or with negatives, shrinks) the sampling mask so the inpainter repaints past your drawn edge. Different job from blend_pixels.
  • invert_mask - inpaint everything outside the drawn region.
  • rescale_algorithm - the filter for the sampler round trip. bilinear is the safe default; nearest never invents pixels.

And the extend_left/right/up/down inputs grow the frame itself for outpainting - the new bands become part of the mask and of the stitched output, which makes this node do outpainting with the same bit-identical guarantee on the original pixels.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/ausboss/ComfyUI-AusBoss.git

Restart ComfyUI and search for AusBoss (ComfyUI Manager: search ComfyUI-AusBoss). No extra Python dependencies for the core pair; fix_edge_halo on the stitch side wants the optional pymatting. Minimum ComfyUI 0.27.1.

Troubleshooting

An empty mask selects the whole image and stitches back unchanged - useful as a passthrough, confusing if you meant to inpaint something and the mask never arrived. If seams show despite a feathered blend, that's blend_pixels being too small or the classic double-blend rim - flip on Stitch Inpaint's fix_edge_halo. And if the crop comes back at the wrong size, check output_multiple isn't rounding it into a different dimension than your sampler expects.

CategoryπŸ†Ž AusBoss/Inpaint

Inputs (17)

NameTypeDefaultDescription
imageIMAGEBHWC image or video frames to crop around the mask.
maskMASKWhite marks the area to inpaint. A multi-frame mask is unioned into one crop window; an empty mask selects the whole image.
context_factorFLOAT1.201–10Grows the mask bounding box symmetrically by this factor so the inpainter sees surrounding context.
blend_pixelsINT160–256Feather width for pasting the result back: the paste mask is widened by this many pixels and blurred. The sampling mask is never feathered. 0 pastes hard.
output_multipleINT81–128Crop and target dimensions are rounded up to a multiple of this so samplers accept them.
target_widthoptINT00–16384Rescale the crop to this width for the sampler; 0 keeps the native crop width (or follows target_height at the crop's aspect ratio).
target_heightoptINT00–16384Rescale the crop to this height for the sampler; 0 keeps the native crop height (or follows target_width at the crop's aspect ratio).
mask_growoptINT0-256–256Dilate the sampling mask by this many pixels (negative shrinks) so the inpainter repaints past the drawn edge. Reshapes what gets painted, unlike blend_pixels which only feathers the paste-back.
mask_bluroptFLOAT0.00–64Gaussian sigma softening the sampling mask's edge for models that honor soft masks. 0 keeps the hard edge.
invert_maskoptBOOLEANfalseInpaint the black area instead of the white area β€” everything outside the drawn region.
context_pixelsoptINT00–4096Flat extra context in pixels added around the mask box after context_factor's growth.
target_megapixelsoptFLOAT0.000–64Rescale the crop for the sampler so its area is about this many megapixels β€” 1.0 suits SDXL-class models, 0 keeps the native crop size. Explicit target_width/height overrides this.
rescale_algorithmoptCOMBObilinearResize filter for the sampler round trip. bilinear is the safe default, bicubic keeps upscales a touch crisper, area suits heavy downscales, nearest never invents pixels.
extend_leftoptINT00–8192Outpainting: grow the frame this many pixels leftward. The new band is added to the mask and becomes part of the stitched output.
extend_rightoptINT00–8192Outpainting: grow the frame this many pixels rightward. The new band is added to the mask and becomes part of the stitched output.
extend_upoptINT00–8192Outpainting: grow the frame this many pixels upward. The new band is added to the mask and becomes part of the stitched output.
extend_downoptINT00–8192Outpainting: grow the frame this many pixels downward. The new band is added to the mask and becomes part of the stitched output.

Outputs (3)

NameTypeDescription
imageIMAGECropped BHWC region around the mask, sized for the sampler.
maskMASKHard-edged sampling mask matching the crop; never feathered.
stitcherAUSBOSS_STITCHERStitch data for Stitch Inpaint πŸ†Ž: canvas, rects, blend mask, scale.