AGSoft Inpaint Crop
Crop tight, inpaint big, stitch it back — the whole trick in one node
- image
- mask
- stitcher
- cropped_image
- cropped_mask
- width
- height
The single best trick in masked inpainting is also the one that takes the most plumbing: crop a small region around your mask, render it at the model's native resolution, then paste the result back so the rest of the frame is bit-identical. AGSoft Inpaint Crop is the first half of that pipeline, and it's the half people usually hand-build with four or five separate nodes. It takes the image and mask, crops a box around the mask with padding, feathers the edges, aligns to model-friendly dimensions, and hands you - along with the crop - a stitcher object that remembers everything needed to put the result back.
It pairs with the pack's AGSoft Inpaint Stitch node, and together they make the crop-and-stitch workflow a two-node graph instead of a mini project.
How it works
The crop box is computed from your mask's bounds. Three settings shape it:
padding(default 32) - extra pixels around the mask so the model has context, not just the masked sliver.force_square(default on) - makes the crop square (sized to the larger side), which most inpainting models want. The tooltip recommends keeping it on.multiple_of(default 64) - rounds the crop up to a multiple; drop to 8 for SD1.5 workflows.
feathering (default 16) blurs the mask edge in the original resolution, which is what makes the later stitch blend instead of showing a hard seam.
Then the optional part: upscale_mode. Inpainting models render best at their native resolution, and your crop may be small - so the node can upscale the cropped image (with target_width/target_height, scale_factor, or fit modes) before it goes to the sampler. The mask stays at original resolution, and the stitcher remembers the scale so Inpaint Stitch can shrink the result back down on paste. That's the whole "64px eye gets 1024px of generation budget" trick, automated.
The outputs
stitcher (a custom STITCHER object carrying original image, offset, and scale), cropped_image, cropped_mask, and width/height ints. The stitcher is the piece you must not lose - it's what lets Inpaint Stitch place the result back exactly.
Where it fits
Wire: AGSoft Inpaint Crop → your sampler (denoise ~1.0 in the masked region) → AGSoft Inpaint Stitch. If you're coming from the instruction-edit era and want bit-identical unmasked pixels - which no edit model gives you - this crop-stitch chain is the standard way to get them with a mask. It also plays fine with the older "dedicated inpainting model" approach.
Installing it
Pack standard: ComfyUI Manager → search comfyui-AGSoft → install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft.git
No model downloads. One dependency note: the Stitch node offers Poisson blending, but only if opencv-python is installed - the pack's requirements.txt doesn't guarantee it, so if the fancier blend is greyed out, pip install opencv-python in your ComfyUI environment.
Common issues
- Cropped region too tight - that's
padding; raise it before blaming the model. - Hard seams after stitch -
featheringtoo low, or the mask edge is sharp at full res. Bump feathering and re-run. - Poisson blend missing - opencv not installed (above).
- Upscale drift - if you upscaled the crop and the stitch looks slightly off-position, check that the
stitcherwire is intact; without it the node can't compute the original offset.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Исходное изображение в формате [B, H, W, C]. Обычно подаётся от Load Image. | |
| mask | MASK | Маска inpainting в формате [B, H, W]. Белое (1.0) — область для редактирования. | |
| padding | INT | 320–256 | Дополнительный отступ (в пикселях) вокруг маски для контекста. Увеличивает область обрезки. |
| feathering | INT | 160–128 | Радиус размытия краёв маски. Улучшает плавность перехода при сшивании. Применяется в оригинальном разрешении обрезки. |
| multiple_of | COMBO | 64 | Размеры обрезки будут округлены вверх до кратного этому числу. Требуется некоторыми моделями (например, SDXL — 64, SD1.5 — 8). |
| force_square | BOOLEAN | true | Если включено, обрезка будет принудительно квадратной (сторона = max(ширина, высота)). Рекомендуется для большинства inpainting-моделей. |
| upscale_mode | COMBO | disabled | Режим апскейла изображения перед inpainting: • disabled — без апскейла (рекомендуется для больших изображений) • to_size — задать точные целевые размеры • scale_by — масштабировать на коэффициент (сохраняя пропорции) • fit_to_width — изменить ширину до заданной, высоту — пропорционально • fit_to_height — изменить высоту до заданной, ширину — пропорционально |
| target_width | INT | 51264–2048 | Целевая ширина изображения после апскейла. Используется в режимах: to_size, fit_to_width. |
| target_height | INT | 51264–2048 | Целевая высота изображения после апскейла. Используется в режимах: to_size, fit_to_height. |
| scale_factor | FLOAT | 1.50.1–4 | Коэффициент масштабирования. Например, 2.0 — увеличить в 2 раза. Используется только в режиме scale_by. |
| upscale_method | COMBO | lanczos | Метод интерполяции при апскейле изображения: • lanczos — наилучшее качество для изображений • bicubic — хорошее качество, быстрее Lanczos • bilinear — быстрее, но ниже качество • nearest — без сглаживания (для пиксель-арта) |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| stitcher | STITCHER | — |
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| width | INT | — |
| height | INT | — |