RefineAnything_PreImg
Crop to the mask, carry the original, and leave the rest of the frame alone
- origin_image
- mask_image
- image
- mask_image
- cond
Qwen-Image-Edit has one sin: it re-emits the whole frame. Ask it to fix a logo and the rest of the photo comes back close but not identical, and that drift compounds the more you edit. RefineAnything is a LoRA built to dodge exactly that - you mark a region, it refines only that region, and the pixels you didn't mark stay bit-for-bit the same. RefineAnything_PreImg is the front half of that pipeline, and honestly the part that makes the whole thing usable.
What it's actually doing
Give it your full image and a mask, and it does three quiet jobs that would otherwise be a fiddly chain of crop, resize, and mask-prep nodes:
- Focus-crops. It finds the mask's bounding box and crops around it so the diffusion model works on roughly a 1024×1024 region instead of your whole 4K photo.
- Re-binarises the mask. Anything above zero becomes pure white, converted to an RGB image the model can read as a spatial condition.
- Bundles the original. It packs the untouched full image, the cropped mask, and the crop coordinates into one
condoutput that the pack's other half,RefineAnything_Pasteback, needs when it's time to stitch back.
That crop is the whole point. Whole-frame editors spend their generation budget everywhere at once, which is why a 64-pixel eye in a big photo comes back mushy. Crop to the mask and that same eye gets 1024 pixels of budget to itself. The crop also gets a 64px margin so the model sees context around the region instead of a razor-sharp cut, and the whole thing stays resolution-independent - big image or small, the edit always runs at a sane size.
The inputs that matter
origin_image- your full photo. Anything ComfyUI considers an IMAGE works.mask_image- a grayscale mask of what you want refined. It doesn't need to be a perfect cutout; the example workflow feeds it straight from ComfyUI's clipspace painting, and SAM or a hand-drawn mask both work. If it's a different size than the image it gets resized to match.do_focus_crop(default on) - turn it off and the node skips the crop entirely, passing the full image through unchanged. Only bother if your whole image already is roughly the generation resolution.
Wiring it up
Outputs are image (the cropped region), mask_image (the binary mask), and cond. The crop feeds the sampler's latent through a VAEEncode and doubles as image 1 of the pack's TextEncodeQwenImageEditPlus_NoAppend node; the mask goes in as image 2; and cond goes straight to RefineAnything_Pasteback. Don't try to preview or save cond - it's not an image, it's a little dict of context, and it only makes sense when it reaches Pasteback from the same run.
Installing
The pack is a single __init__.py with zero extra Python dependencies - ComfyUI's own einops, PIL and torch cover it. Via ComfyUI Manager search for ComfyUI_RefineAnything, or:
cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_RefineAnything
Restart and the three nodes appear. The heavy lift is models: the Qwen-Image-Edit-2511-RefineAny.safetensors LoRA from the limuloo1999/RefineAnything Hugging Face repo into models/lora/, plus the normal Qwen-Image-Edit-2511 diffusion model, CLIP and VAE, and a 4-step Lightning LoRA if you want the example workflow's fast sampling. That's a 20B model - on a consumer card you'll be running a GGUF quant, not the bf16 weights.
Troubleshooting
- "Mask is empty - nothing to refine." That's the node's one hard error, and it means your mask is entirely black. Paint something, or check that the mask input isn't a solid-black tensor.
- The edit comes back blurry. You're probably feeding the full image at its native size with
do_focus_cropoff. Turn it back on - the crop is the resolution fix. - Colors shift in the patched region. That's the stitching stage's problem, not this node's - head over to the Pasteback article for the color-fix knobs.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| origin_image | IMAGE | — | |
| mask_image | IMAGE | — | |
| do_focus_crop | BOOLEAN | true | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask_image | IMAGE | — |
| cond | CONDITIONING | — |