Nodes/ComfyUI-DaSiWa-Nodes/DaSiWa Inpaint Crop Prep
ComfyUI Node

DaSiWa Inpaint Crop Prep

DaSiWa Inpaint Crop Prep

By darksidewalker·Created 5 months ago·Updated 4 days ago· 109
DaSiWa Inpaint Crop Prep
  • image
  • mask
  • cropped_image
  • cropped_mask
  • bbox_x
  • bbox_y
  • bbox_w
  • bbox_h
target_width1024
target_height1024
mask_blur4.0
mask_min0.01
mask_max1.00
grow_px32
can_shrinktrue

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:

  1. Gaussian-blurs the mask (mask_blur, default 4) to feather the edges, then clamps it to mask_minmask_max so faint mask noise doesn't inflate the crop.
  2. 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.
  3. 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_min or 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_width is below the crop's native size and can_shrink is on, you're downscaling your fix and losing the detail advantage. Turn off can_shrink when the region is already large.
CategoryDaSiWa/Inpaint

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
maskMASK
target_widthINT102464–8192
target_heightINT102464–8192
mask_blurFLOAT4.00–64
mask_minFLOAT0.010–1
mask_maxFLOAT1.000–1
grow_pxINT320–2048
can_shrinkBOOLEANtrue

Outputs (6)

NameTypeDescription
cropped_imageIMAGE
cropped_maskMASK
bbox_xINT
bbox_yINT
bbox_wINT
bbox_hINT