Inpaint Crop [LP]
The crop half of the crop-edit-stitch inpainting pattern
- image
- mask
- optional_context_mask
- extend_factor_parameters
- cropped_size_parameters
- crop_data
- cropped_image
- cropped_mask
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 yourtarget_size(default 1024).forced sizepins exactly toforce_width/force_heightinstead;input size parametersstays closer to source scale;noneskips 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).
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| downscale_algorithm | COMBO | bilinear | 6 options: nearest, bilinear, bicubic, lanczos, box, hamming |
| upscale_algorithm | COMBO | bicubic | 6 options: nearest, bilinear, bicubic, lanczos, box, hamming |
| mask_fill_holes | BOOLEAN | true | Mark as masked any areas fully enclosed by mask. |
| mask_expand_pixels | INT | 00–16384 | Expand the mask by a certain amount of pixels before processing. |
| mask_invert | BOOLEAN | false | Invert mask so that anything masked will be kept. |
| mask_blend_pixels | INT | 320–64 | How many pixels to blend into the original image. |
| mask_hipass_filter | FLOAT | 0.100–1 | Ignore mask values lower than this value. |
| context_from_mask_extend_factor | FLOAT | 1.201–100 | Grow 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_padding | COMBO | 32 | 8 options: 0, 8, 16, 32, 64, 128, +2 |
| mode | COMBO | aspect size | 4 options: none, input size parameters, forced size, aspect size |
| target_size | INT | 10240–16384 | — |
| aspect_ratio_limit | FLOAT | 2.001–100 | — |
| force_width | INT | 10240–16384 | — |
| force_height | INT | 10240–16384 | — |
| maskopt | MASK | — | |
| optional_context_maskopt | MASK | — | |
| extend_factor_parametersopt | EXTENDFACTORDATA | — | |
| cropped_size_parametersopt | CROPPEDSIZEDATA | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| crop_data | CROPDATA | — |
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |