Nodes/ComfyUI-QG-tools/Crop For Inpaint
ComfyUI Node

Crop For Inpaint

Cuts the painted area out with room around it, at a size the sampler accepts, and emits a stitcher that Stitch Inpaint uses to paste the result back seamlessly. context_factor grows the painted box symmetrically so the model sees its surroundings; context_pixels adds flat pixels on top of that. blend_pixels feathers only the paste-back -- mask_grow and mask_blur are what reshape the sampling mask. target_megapixels, or explicit target_width/target_height, rescale the crop for the sampler; extend_left/right/up/down grow the frame itself, which is how this pair outpaints. An empty mask selects the whole picture and stitches back unchanged. Unlike Mask Crop, which is plain geometry restored by Crop Restore, this keeps the data a seam needs: tone match, edge-halo recovery and a fade across the picture's own edge.

By live1617·Created 23 days ago·Updated 2 days ago· 4
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►
◄keep_insidetrue►
CategoryQG-tools/Retouch

Inputs (18)

NameTypeDefaultDescription
imageIMAGEBHWC picture, or the frames of a clip, to cut from.
maskMASKWhite marks what the model should paint. Several frames are unioned into one crop window. A mask of the wrong size is an error, but the 64x64 stand-in core Load Image hands over when nothing was painted counts as empty, not wrong: it selects the whole picture.
context_factorFLOAT1.201–10Grows the painted box by this factor so the inpainter sees surrounding context. 1.0 hugs the paint exactly.
blend_pixelsINT160–256Feather width for pasting the result back: the paste mask is widened by this many pixels and blurred. It never touches the sampling mask; 0 pastes hard.
output_multipleINT81–128Crop and target dimensions are rounded up to a multiple of this so samplers accept them. 8 keeps latent sizes legal.
target_widthoptINT00–16384Rescale the crop to this width for the sampler; 0 keeps the native 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 height, or follows target_width at the crop's aspect ratio.
mask_growoptINT0-256–256Dilate the sampling mask by this many pixels (negative shrinks it) 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 honour soft masks. 0 keeps the hard edge.
invert_maskoptBOOLEANfalsePaint the black area instead of the white one - everything outside the drawn region.
context_pixelsoptINT00–4096Flat extra context in pixels, added around the box after context_factor's growth.
target_megapixelsoptFLOAT0.000–64Rescale the crop so its area is about this many megapixels: 1.0 suits SDXL-class models, 0 keeps the native crop size. Explicit target_width/height win.
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 joins the mask and becomes part of the stitched output.
extend_rightoptINT00–8192Outpainting: grow the frame this many pixels rightward.
extend_upoptINT00–8192Outpainting: grow the frame this many pixels upward.
extend_downoptINT00–8192Outpainting: grow the frame this many pixels downward.
keep_insideoptBOOLEANtrueKeep the crop inside the picture. On, the context stops at the picture's edges, so the model sees only real pixels. Off, the crop runs past them, filled with stretched copies of the edge pixels.

Outputs (3)

NameTypeDescription
imageIMAGEThe crop around the painted area, sized for the sampler.
maskMASKThe sampling mask, cropped like the picture: the input mask after invert, grow and blur. blend_pixels never feathers it.
stitcherAUSBOSS_STITCHERStitch data for Stitch Inpaint: canvas, rects, paste mask, scale. Works with AusBoss's Stitch Inpaint too - the socket type and the stitcher format are shared on purpose.