Nodes/ComfyUI Level Pixel/Inpaint Crop [LP]
ComfyUI Node

Inpaint Crop [LP]

The crop half of the crop-edit-stitch inpainting pattern

By LevelPixel·Created 2 years ago·Updated 6 months ago· 31
Inpaint Crop [LP]
  • image
  • mask
  • optional_context_mask
  • extend_factor_parameters
  • cropped_size_parameters
  • crop_data
  • cropped_image
  • cropped_mask
downscale_algorithmbilinear
upscale_algorithmbicubic
mask_fill_holestrue
mask_expand_pixels0
mask_invertfalse
mask_blend_pixels32
mask_hipass_filter0.10
context_from_mask_extend_factor1.20
output_padding32
modeaspect size
target_size1024
aspect_ratio_limit2.00
force_width1024
force_height1024

This is the flagship node in the whole Level Pixel pack, and it's not a Level Pixel original - the README says so plainly: "the core functionality is taken from ComfyUI-Inpaint-CropAndStitch and belongs to its authors," crediting lquesada's project directly. What you're getting is a ported, integrated copy of the pattern that basically won inpainting in ComfyUI over the last year or so: crop, edit, stitch.

Why this pattern took over

Nobody designed the crop-edit-stitch workflow as a grand plan - it emerged because instruction-editing models (Qwen-Image-Edit, Flux Kontext, Flux 2 Klein) got good enough to replace mask-based inpainting for most jobs, except for one thing they can't do: leave the rest of the image alone. An edit model re-encodes and regenerates the whole frame, so even unmasked pixels drift a little, and that drift compounds if you're chaining multiple edits. Masked inpainting doesn't have that problem - but writing it by hand, correctly, is fiddly.

Inpaint Crop is the "correctly" part. It finds the region around your mask, optionally pads it with extra context, resizes it to a clean working resolution, and hands you back a small cropped fragment plus a bundle of crop metadata. You run anything on that fragment - a sampler, an edit model, a manual repaint - and then this pack's InpaintStitch-LP puts it back into the original image using that metadata. Critically, the unmasked part of the original image is never touched, never re-encoded, never re-decoded through a VAE - it's compositing, not regeneration. That property is the entire reason this pattern displaced hand-rolled masked inpainting.

The inputs and outputs that matter

The node has a lot of fields, but a handful actually drive the result:

  • mode and target_size - the big lever. Default mode is aspect size, which auto-computes a working resolution that respects the masked region's own aspect ratio while hitting your target_size (default 1024). forced size pins exactly to force_width/force_height instead; input size parameters stays closer to source scale; none skips resizing entirely.
  • context_from_mask_extend_factor (default 1.2) - how much surrounding area to grab beyond the mask itself, as a multiplier. The tooltip's own example: 1.5 grabs an extra 50% in every direction. Push this down toward 1.0 if the crop keeps grabbing more of the image than you want; raise it if the model needs more surrounding context to blend convincingly.
  • mask_blend_pixels (default 32, capped at 64) - how many pixels get feathered at the seam when the fragment goes back in. This is your main knob for a visible seam.
  • mask_hipass_filter (default 0.1) - ignores mask values below this threshold, so faint stray mask noise doesn't get treated as "masked."
  • mask_fill_holes and mask_expand_pixels/mask_invert - the standard mask-cleanup trio: fill enclosed gaps, grow the mask by N pixels, or invert what counts as masked.

Optional inputs include mask (you'll basically always want one) and optional_context_mask for keeping extra area visible without it being part of what gets edited.

Outputs: crop_data (feed this straight into InpaintStitch-LP, don't modify it), plus cropped_image and cropped_mask - the actual pixels you run your sampling or editing on.

How to install it

ComfyUI Manager: search "ComfyUI Level Pixel" or ComfyUI-LevelPixel, install, restart - auto-updates through Manager's "Update ALL." Manual:

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

Restart ComfyUI. No model downloads - this is pure image/mask math, ported code, nothing extra to fetch.

Common issues & troubleshooting

You're feeding this into a modern edit model (Qwen-Image-Edit, Flux Kontext/Klein) and it's not doing "true" masked inpainting. By default, an edit model just edits the whole cropped fragment, which isn't the same as respecting the mask inside it. The fix the community settled on: use an InpaintModelConditioning node instead of an empty latent when you build your sampling graph on the cropped output, and use a Basic Scheduler (Simple) rather than a model-specific scheduler so you keep access to a real denoise-strength dial.

Visible seam where the fragment was stitched back. Raise mask_blend_pixels for a wider feather - it's capped at 64, so if that's not enough, you likely need a softer mask going in rather than more blend at the edge.

Mask is "leaking" into areas that should read as unmasked. That's what mask_hipass_filter exists for - raise it slightly above the 0.1 default if your mask source is noisy (e.g., coming from an automated segmentation model rather than hand-painted).

CategoryLevelPixel/Inpaint

Inputs (19)

NameTypeDefaultDescription
imageIMAGE
downscale_algorithmCOMBObilinear6 options: nearest, bilinear, bicubic, lanczos, box, hamming
upscale_algorithmCOMBObicubic6 options: nearest, bilinear, bicubic, lanczos, box, hamming
mask_fill_holesBOOLEANtrueMark as masked any areas fully enclosed by mask.
mask_expand_pixelsINT00–16384Expand the mask by a certain amount of pixels before processing.
mask_invertBOOLEANfalseInvert mask so that anything masked will be kept.
mask_blend_pixelsINT320–64How many pixels to blend into the original image.
mask_hipass_filterFLOAT0.100–1Ignore mask values lower than this value.
context_from_mask_extend_factorFLOAT1.201–100Grow the context area from the mask by a certain factor in every direction. For example, 1.5 grabs extra 50% up, down, left, and right as context.
output_paddingCOMBO328 options: 0, 8, 16, 32, 64, 128, +2
modeCOMBOaspect size4 options: none, input size parameters, forced size, aspect size
target_sizeINT10240–16384
aspect_ratio_limitFLOAT2.001–100
force_widthINT10240–16384
force_heightINT10240–16384
maskoptMASK
optional_context_maskoptMASK
extend_factor_parametersoptEXTENDFACTORDATA
cropped_size_parametersoptCROPPEDSIZEDATA

Outputs (3)

NameTypeDescription
crop_dataCROPDATA
cropped_imageIMAGE
cropped_maskMASK