Nodes/ComfyUI-Image-Inpainting/ImagePreprocess Inpaint
ComfyUI Node

ImagePreprocess Inpaint

The unglamorous resize that keeps masks honest

By SherryXieYuchen·Created 2 years ago·Updated 2 years ago· 4
ImagePreprocess Inpaint
  • image
  • IMAGE
max_length1024

"ImagePreprocess Inpaint" is the pack's answer to a boring but fatal problem: inpainting needs the image and the mask to be exactly the same size, and your source image is probably bigger than anything you want to run through a sampler. This node downscales an image to a manageable max_length - but only if it's actually over the limit. Small images pass through untouched.

The workflow uses it twice, and that's the part to copy. The original image goes through one instance, and the mask goes through another (after being converted to an image and back), both at the same max_length - so the two arrive at the VAE encode step at identical resolution. Skip that symmetry and you get the classic silent failure: a resize error, or worse, a mask that's misaligned with the image by a few pixels, which then shows up as a smeared edge on the inpainted region. The KB's inpainting essay calls mask/image alignment one of the first things to check when seams appear, and this node exists to make it a non-issue.

How it works

Two inputs: image and max_length. It measures the longer side; if it's already at or under max_length, the image is returned as-is. If it's over, the image is rescaled so the longer side lands exactly on max_length, keeping the aspect ratio, using Lanczos (cv2.INTER_LANCZOS4) - the good resize filter, the one that doesn't smear fine detail the way bilinear can.

The max_length range (512–1024, step 8) is a nice touch: the step of 8 keeps dimensions friendly to SD 1.5's latent grid, and the upper cap matches the resolution the bundled workflow actually samples at (768). In the graph it feeds INPAINT_VAEEncode, which then does its own multiple-of-8 padding - the two work together so nothing ever hits the VAE at a hostile size.

Install

Standard for this pack - Manager → search "ComfyUI-Image-Inpainting", or:

cd ComfyUI/custom_nodes
git clone https://github.com/SherryXieYuchen/ComfyUI-Image-Inpainting
# restart ComfyUI

No models, no dependencies beyond the cv2 that ships with ComfyUI. It's pure image transform.

Where to trip

  • Preprocess image and mask to the same max_length. This is the entire point; the moment the two diverge, downstream masking goes fuzzy. The workflow converts the mask to an image, preprocesses it, then converts back - follow that pattern.
  • This only downscales. It never upscales a small image to reach max_length; a 600px image at max_length 768 stays 600px. If you need the crop to hit a specific size, that's what ImagePostprocess (the upscale/rescale twin) is for.
  • Single image in, single image out - squeeze(0) throughout, so feed one frame at a time.
Categoryimage/transform

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
max_lengthINT1024512–1024

Outputs (1)

NameTypeDescription
IMAGEIMAGE