Nodes/ComfyUI-DonutNodes/Donut Inpaint · Keep Surroundings
ComfyUI Node

Donut Inpaint · Keep Surroundings

The one node that makes a Krea 2 area edit actually stay an area edit

By DonutsDelivery·Created about a year ago·Updated about 11 hours ago· 25
Donut Inpaint · Keep Surroundings
  • image
  • inpaint
  • image

You painted a selection, you told the model to change one thing, and it did - along with quietly re-rendering the other 90% of the frame. That's every instruction edit model. The mask is a guarantee about the pixels you didn't select, not a suggestion, and that's why masked inpainting is still around in 2026.

Donut Inpaint · Keep Surroundings (DonutInpaintComposite) is the node that enforces that guarantee inside DonutNodes' Krea 2 edit stack. It takes whatever your finishing stage just produced - the base decode, an upscale, a Face Detailer pass - and pastes image A back everywhere outside your Edit Studio selection. Donut's edit path is a community identity-edit LoRA on top of Krea 2, not a purpose-built masked editing model, so the whole frame comes back regenerated every time. This node is the correction.

How it works

The node is almost aggressively simple. One required input, image, one optional input, inpaint. The inpaint socket takes a DONUT_INPAINT bundle from Edit Studio's inpaint output: a dict holding the cropped reference A plus the painted mask, rasterized in A's own coordinates and cropped to the same box as A. The same bundle feeds edit_inpaint on the Donut sampler, which seeds preserved regions and sets a step noise mask so only your selection gets denoised.

At execution it does a straight alpha blend: image * mask + base * (1 - mask). Mask outside the painted area is exactly zero, so those pixels come back as base pixels - bit-identical, no VAE round trip, no model opinion. If image and the stored base differ in size (upscale 1.5×, 2×), the base is resized bicubically and the mask bilinearly before blending.

If inpaint isn't connected - because you turned selected-area editing off, or you're not editing at all - the node returns image untouched. It's a pass-through. Don't sit there wondering why it "isn't doing anything."

The single output is image; wire it wherever the stage would have gone.

Where it sits in the graph

Four of them ship in the V4 Beta workflow, all titled "Keep surroundings from A" - after base decode, after each of the two upscales, and after Face Detailer. That's the pattern, and it matters: compositing once at the end can't undo drift that happened in between, because every downstream stage re-encodes the whole frame.

One honest caveat, straight from the pack's own docs: at the same output size those restored pixels are the original cropped pixels from A; at a larger output size they're resized pixels from A. The unselected region gains no generative upscale detail. You're preserving fidelity, not resolution - perfect when the job is "change her jacket, keep the background stock-photo clean," wrong if you hoped the surroundings would sharpen with the upscale.

Save PNG or lossless WebP if you want that preservation to survive to disk. WebP at quality 100 is still lossy.

Installing it

It's part of DonutNodes, so there's nothing extra to fetch. In ComfyUI Manager, search for DonutNodes and install. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/DonutsDelivery/ComfyUI-DonutNodes.git donutnodes
cd donutnodes
python -m pip install -r requirements.txt

Use the interpreter that actually launches ComfyUI, restart, hard-refresh the browser. This module only needs numpy, PIL and torch, but the pack wants opencv-python-headless>=4.10.0.84, scipy>=1.13.1, matplotlib>=3.9.2, plus psutil, tqdm and requests. Two flags from the pack's dependency doc: never let it pin or downgrade NumPy globally, and keep exactly one package providing cv2 - OpenCV variants collide. No model downloads here - those come from the workflow's Krea 2 setup and the identity-edit LoRA.

One Donut-specific gotcha: the README separates the V4 Beta workflow release from the DonutNodes package version. If Edit Studio or Donut Image Save are missing from your node list, your install predates the beta, and this node's inpaint input has nothing to connect to until Edit Studio exists. Update the checkout rather than making a second node folder.

Things that bite

Replacing image A resets the saved selection; B can change independently. If your strokes were painted for the previous A, Edit Studio throws "Paint a mask for the current image A." An empty selection won't silently become a whole-image edit either - it errors with "Paint the area to edit on image A, or turn selected-area editing off."

On the sampler side, mismatches surface as "Connect Edit Studio width and height to the inpaint target; its mask must match image A." or a complaint that the encoded base has to be a single B,C,H,W image - the DONUT_INPAINT bundle arriving at the wrong dimensions. Feed the sampler's width/height from Edit Studio rather than typing them in.

Drag the seam width to zero and you get a hard edge. Feather is inward-only: the softness is carved out of the inside of the selection so the outside stays exactly zero. No bleed into the region you asked to protect - a visible seam is yours to fix by widening the band.

Categorydonut/editing

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
inpaintoptDONUT_INPAINT

Outputs (1)

NameTypeDescription
imageIMAGE