Nodes/ComfyUI-GTF-Utilities/Mask-Crop Inpaint | Pre
ComfyUI Node

Mask-Crop Inpaint | Pre

Mask, crop, and prep

By wmpmiles·Created 2 years ago·Updated about a year ago· 5
Mask-Crop Inpaint | Pre
  • image
  • mask
  • resampler
  • scaler
  • image
  • mask
  • latent_mask
  • context
squaretrue
area_mult1.0
color_shift0.50

Mask-Crop Inpaint | Pre is the front half of this pack's crop-and-stitch inpainting workflow, and it does the thing that makes mask inpainting worth doing at all: it crops to a bounding box around your mask, resizes that region to a model-friendly size, and preps everything for the sampler. Pair it with Mask-Crop Inpaint | Post and you get the "only-masked detail at full resolution" superpower - a 64-pixel eye gets 1024 pixels of generation budget, and the untouched pixels outside the crop never move.

Why crop at all? The inpainting essay makes the case: whole-frame editing drifts - unmasked regions come back close but not identical. Masked inpainting composites the new pixels back and leaves everything else bit-identical. Cropping to the region first is what lets the model spend its entire resolution budget on the area you actually changed, and it's faster and more VRAM-friendly than running the full image.

How it works

The node takes the image, the mask, and - like the resampling family - a resampler and a scaler to control the crop's target size. It computes a bounding box from the mask, optionally squares it, expands it by area_mult, crops both image and mask, resizes the crop through your chosen resampler/scaler, then does three quiet but crucial steps:

  1. Pads to a multiple of 8 (reflect for the image, zero for the mask) so the latent side stays on the VAE's grid.
  2. Color-shifts the image by the color_shift amount (default 0.5). This is the "fill the masked region with ~0.5 gray" trick that non-zero-terminal-SNR models like SDXL need for clean full-denoise inpainting. Set it to 0.0 to disable.
  3. Produces a latent_mask already resized to 1/8 resolution (nearest-neighbor, no smearing) so you can mask the latent directly.

Outputs are image, mask, latent_mask (all cropped/resized for the sampler), and context - an opaque bundle that Mask-Crop Inpaint | Post requires to paste the result back. You must wire that context straight from Pre to Post; it's how the crop gets undone.

The inputs that matter

  • square (default true) - force the crop bounding box to be square. Almost always leave it on; models hate extreme aspect ratios.
  • area_mult (default 1, min 1) - how much to expand the bounding-box area beyond the mask. 1 hugs the mask tight; 1.5–2 gives the model breathing room around the region, which usually reads as better blending.
  • color_shift (default 0.5) - leave at 0.5 for SDXL-family models; drop to 0 if your model handles inpainting without it or you're getting washed-out crops.

The resampler/scaler pair is the same architecture as the rest of the pack: pick e.g. Scaler | Fixed (a good inpaint crop size) and Resampler | Lanczos. If the mask and image aren't the same resolution, or the mask has a batch size other than 1, the node errors - check that before you debug anything else.

Installing

Part of comfyui-some-image-processing-stuff:

cd ComfyUI/custom_nodes
git clone https://github.com/wmpmiles/comfyui-some-image-processing-stuff

Restart, or ComfyUI Manager → "Some Image Processing Stuff". No models, no extra deps. The whole pack clones at once, so Post, the scalers, and the resamplers arrive together - you need all of them for this workflow.

Categoryinpaint

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
maskMASK
resamplerRESAMPLER
scalerSCALER
squareBOOLEANtrue
area_multFLOAT1.0
color_shiftFLOAT0.500–1

Outputs (4)

NameTypeDescription
imageIMAGE
maskMASK
latent_maskMASK
contextCONTEXT