Nodes/ComfyUI_AnyDoor/AnyDoor_img2img
ComfyUI Node

AnyDoor_img2img

Paste an object into a new scene with AnyDoor_img2img

By smthemex·Created 2 years ago·Updated 2 years ago· 69
AnyDoor_img2img
  • ref_image
  • ref_mask
  • tar_image
  • tar_mask
  • model
  • ddim_sampler
  • image
info
cfg9.0
seed0
steps30
control_strength1.00
width512
height512
batch_size1
enable_shape_controlfalse
use_interactive_segfalse

AnyDoor_img2img is the reason anyone installs ComfyUI_AnyDoor. It takes an object - plus a mask that says "this is the object" - from one image, and transplants it into another image at a mask you draw there. The two headline uses come straight from the pack's README: changing a character's clothes, and moving an object to a new position in the same picture. Same mechanism, two jobs.

The honest 2026 caveat up front: AnyDoor is Alibaba's December 2023 model, and even back then the community verdict was "functional, but the quality isn't quite there." A modern instruction-edit model - Qwen-Image-Edit, Flux Klein - will do "put a helmet on him" from a sentence with no masks at all. So why bother? Because those models re-render the whole frame. AnyDoor composites its result back over the original pixels outside the target mask, which stay bit-identical - the same guarantee that's kept masked inpainting alive while sentence-editors took over everything else. If you need an object placed exactly and the background untouched, this is the tool.

How it works

Before anything runs, wire in the three outputs from AnyDoor_LoadModel - model, ddim_sampler, and the info string are all required inputs, and info is forceInput, so leaving it unplugged means the node won't even execute.

The pipeline explains every failure mode you'll hit:

  • A frozen DINOv2 ViT-g encoder reads the reference object (cropped to its mask, squashed to 224×224) to capture identity.
  • A sobel-edge collage of that object becomes a ControlNet-style "hint" carrying shape, composited onto the target at your target mask's position.
  • A DDIM sampler runs inside that region at the width/height you set, then the result is cropped back into the original target image. Background untouched by construction.

The inputs that matter

  • ref_image + ref_mask - the object you're moving. The mask should hug the object tightly; whiter means selected, and the README warns that masks are also how the model knows what to grab.
  • tar_image + tar_mask - the scene, and where the object lands. The target mask is the single most important input: it sets both the position and the rough footprint.
  • cfg (default 9) - high, and that's AnyDoor's stock default, not a typo. If output comes out mushy, check this before you blame the model.
  • steps (default 30), control_strength (default 1) - the strength dial scales how hard the identity/shape control pushes across the UNet blocks. Crank it down when the transplanted object is overwhelming the scene.
  • seed - it's in the schema, but the README says it's currently invalid, and nothing in the code uses it. Don't burn an afternoon chasing seed variations.
  • width/height - default 512, multiples of 64. The model trained at 768×768 max; the README explicitly warns against oversized images.
  • enable_shape_control / use_interactive_seg - both default off for good reasons. The first makes the placement follow your target mask more tightly; the second re-processes the mask with a bundled refine model, and the author recommends leaving it off unless you're feeding hand-drawn animation masks.

Output is a single image - wire it into Save Image (or Preview Image).

Install and models

Same pack, same story as the loader: install via ComfyUI Manager or git clone https://github.com/smthemex/ComfyUI_AnyDoor.git, then pip install -r requirements.txt (just modelscope, open_clip_torch, pytorch_lightning). The first run auto-downloads roughly 9.4 GB of weights from modelscope into ComfyUI/models/anydoor/; if that stalls, pre-download the pruned checkpoint and dinov2_vitg14_pretrain.pth into that folder yourself. Use the pruned checkpoint in the loader - the 16.8 GB origin file buys nothing but VRAM pain.

Common issues

  • The object looks pasted-on, or background bleeds in → your ref mask is sloppy. Hand-drawn masks work, but the README's advice is worth taking: SAM/Seg-generated masks give the model a clean object to read. Keep the selected area white.
  • Node won't run → the info string from the loader must be connected. It's a required input disguised as an afterthought.
  • Object ignores where you put it → raise control_strength and check the target mask covers exactly where the object should sit.
  • VRAM death on large images → keep width/height around 512, tick save_memory on the loader, and make sure you're on the pruned checkpoint.

That's the whole workflow: masks in, object moves, background survives. Just don't expect it to beat a 2026 edit model on quality - it wins on control, not on fidelity.

CategoryAnyDoor

Inputs (16)

NameTypeDefaultDescription
ref_imageIMAGE
ref_maskIMAGE
tar_imageIMAGE
tar_maskIMAGE
modelMODEL
ddim_samplerMODEL
infoSTRING
cfgFLOAT9.00–30
seedINT00–18446744073709550000
stepsINT301–10000
control_strengthFLOAT1.000–2
widthINT512256–2048
heightINT512256–2048
batch_sizeINT11–12
enable_shape_controlBOOLEANfalse
use_interactive_segBOOLEANfalse

Outputs (1)

NameTypeDescription
imageIMAGE