DaSiWa Inpaint Crop Prep
DaSiWa Inpaint Crop Prep
- image
- mask
- cropped_image
- cropped_mask
- bbox_x
- bbox_y
- bbox_w
- bbox_h
If you've ever tried to fix a face or a hand by inpainting the whole image, you know the problem: the model spends most of its resolution budget on pixels you don't care about, and the tiny region you actually want to fix gets upscaled mush. The fix is the "only masked" trick - crop tight to the mask, render that crop at your inpainter's native resolution, then composite it back. That's exactly what DaSiWa Inpaint Crop Prep is: the first half of a crop-inpaint-composite pair, and it does the crop so you don't have to hand-wire a mask-to-bbox chain yourself.
This is the same pattern the community converged on via lquesada's Inpaint-CropAndStitch: render only the masked region at full detail, and leave every unmasked pixel byte-identical. DaSiWa's version lives in the same pack as its sibling DaSiWa Inpaint Composite, so the pair is a two-node workflow rather than a three-extension plumbing job.
How it works
Feed it an IMAGE and a MASK, and it runs a short pipeline:
- Gaussian-blurs the mask (
mask_blur, default 4) to feather the edges, then clamps it tomask_min–mask_maxso faint mask noise doesn't inflate the crop. - Extracts the mask's bounding box and pads it by
grow_px(default 32) so the model has context around the fix - the community standard of 32–64px padding. - Crops image and mask to that box, then bicubic-scales both up to
target_width×target_height(defaults 1024×1024).
Because it's pure PyTorch - separable Gaussian blur, F.interpolate bicubic - there are no torchvision or extra dependencies to fight.
The inputs that matter
For a beginner, most of the defaults are fine. The two you'll actually touch:
target_width/target_height- the resolution your inpainter wants. Set them to the model's native res (1024 for SDXL/Flux-era models), not the full image's res. This is the whole point: a small crop gets a big generation budget.grow_px- how much context surrounds the fix. Too small and you get seams and style mismatch; too large and you're back to whole-image inpainting.
Worth knowing: can_shrink (default on) lets the crop be downscaled to fit the target. Turn it off if your source crop is smaller than the target and you want to keep it at native size - e.g. a high-res source where the mask region already exceeds 1024px.
The outputs and the other half
You get cropped_image and cropped_mask to feed any inpainter - this is model-agnostic, from SD 1.5 to FLUX.1 Fill to LanPaint. The other four outputs, bbox_x, bbox_y, bbox_w, bbox_h, are the original-image-space coordinates of the crop, and they're what let you paste the result back:
IMAGE + MASK ──► Inpaint Crop Prep ──► cropped_image, cropped_mask
──► any inpainter ──► source patch
IMAGE ───────────────────────────────────────────────┐
▼
DaSiWa Inpaint Composite (x, y, w, h)
▼
IMAGE
Wire the bbox outputs into the Composite's x/y/w/h inputs and it lands exactly where it came from.
Installing it
The usual two routes, same for every node in the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/darksidewalker/ComfyUI-DaSiWa-Nodes
pip install -r requirements.txt
then restart ComfyUI. Or search DaSiWa-Nodes in ComfyUI Manager and install from there. This specific node is pure PyTorch, so the pack's stated NVIDIA RTX requirement (drivers 530+) only really bites if you use the pack's RTX upscaler - not for inpainting.
Where people get burned
- "Mask is empty" error. The node raises if no mask pixels clear the 0.5 threshold. That usually means your mask got inverted somewhere upstream, or it's so soft that blur pushed everything below threshold. Raise
mask_minor check the mask you're actually wiring in. - Forgetting the composite. Inpaint the crop, forget to paste it back, and you have a tiny patch and a mystery. The second node exists for a reason - use it, or at minimum ImageCompositeMasked.
- Target resolution that's smaller than the fix. If
target_widthis below the crop's native size andcan_shrinkis on, you're downscaling your fix and losing the detail advantage. Turn offcan_shrinkwhen the region is already large.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| target_width | INT | 102464–8192 | — |
| target_height | INT | 102464–8192 | — |
| mask_blur | FLOAT | 4.00–64 | — |
| mask_min | FLOAT | 0.010–1 | — |
| mask_max | FLOAT | 1.000–1 | — |
| grow_px | INT | 320–2048 | — |
| can_shrink | BOOLEAN | true | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| bbox_x | INT | — |
| bbox_y | INT | — |
| bbox_w | INT | — |
| bbox_h | INT | — |