Qwen Edit Mask (WepeNerd)
Qwen Edit Has No Mask Input — So Draw One and Show It the Region
- image
- image
- source
- mask
- mask_image
- prompt
The hole this node plugs
Qwen-Image 2.1 edits by instruction, which means there's no mask socket to fill in. You type what you want changed and the model re-emits the whole frame. That's the deal with every editor in this family: you give up the mask, and you give up any guarantee about the pixels you didn't ask about. Faces drift, details in the corner quietly move, and it compounds across a chain of edits.
The fix the community settled on is to bolt a mask back on - keep the instruction-following, but composite so only your region is allowed to change. Qwen Edit Mask is the front half of that pattern. It hands the model a drawing of the region plus a prompt explaining what the drawing means, because a reference-based encoder can't take a MASK tensor - it takes images.
How it works
You paint on the image in the node's own editor - same editor as Paint Mask, so brush, rectangle, eraser, Size, Softness, Opacity, Undo, Clear and a grayscale toggle to inspect raw coverage. There's also a Fill enclosed areas bucket if you'd rather loop an object and fill it in one click. The painting is stored in the workflow, not as a second file you have to remember.
That coverage then becomes what the model actually sees, according to guide:
- outline draws an antialiased ring hugging the region from outside, so the thing you're editing stays visible. This is the default and the one to reach for most of the time.
- tint lays the colour over it at 50% - the region is still readable.
- solid paints over it completely. Good for replacing an object, since you're deliberately hiding what's there.
- none (use mask_image) leaves
imageclean and expectsmask_imagewired to the encoder'simage_2instead.
Everything is then resized to the Qwen reference grid the same way the Text Encode Qwen Image 2.1 node does it: roughly resolution × resolution pixels, multiples of 32, aspect ratio preserved. At 1024, a 1920×1080 shot becomes 1376×768, not 1920×1080. Set resolution to 0 and you keep the image's own size rounded down to a multiple of 32 - a 1000px-wide image comes out 992. The editor footer shows the size after the arrow, so you can see what you're getting.
Finally, prompt wraps your instruction with a description of the guide, in the slot syntax the encoder expects, and asks the model to leave everything else alone: In <image1>, edit only the area inside the red outline: replace it with a glass vase. Remove the red outline. Keep everything outside that area unchanged.
The fields you actually set
Most of this node is the editor, so ignore anything you don't recognise. mask_data is the painting payload the editor writes; you never type in it. The handful that matter:
- instruction - what should happen inside the region, in plain language.
- guide / color - how the region is shown, and in what colour. Pick a colour that doesn't already occur in the region, or the model has to guess which red you meant.
- resolution - the reference-grid size, per above.
fill_holes is on by default, which is what makes "draw a rough loop around the object" actually select the whole object. line_px sets outline thickness in output pixels. The optional image input takes the thing you want to edit.
Four of the five outputs do real work. image is your source with the guide drawn in - that goes to image_1 on the encoder, and prompt goes to prompt. mask is the painted coverage at output size and source is the clean version at the same size; those two go to Qwen Edit Align Composite so pixels outside the mask are copied back exactly. mask_image is for the none guide mode only.
Install
ComfyUI Manager, search ComfyUI-WepeNerd. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/WepeNerd/ComfyUI-WepeNerd.git
cd ComfyUI-WepeNerd
python -m pip install -r requirements.txt
Then restart ComfyUI and hard-refresh the browser. That requirements.txt is Pillow, numpy, SciPy and PyAV - SciPy is not optional here, since it computes the outline ring (distance_transform_edt) and the hole filling. No models, no GPU wheels, no external runtimes; Torch comes from ComfyUI. The pack was tested against ComfyUI 0.34.0 and frontend 1.51.10.
Wiring it, and where people get burned
image→image_1,prompt→prompton Text Encode Qwen Image 2.1, and set that node'sresolutionto 0. If it resizes a second time, your guide lands somewhere other than where you painted.- Sample from the encoder's
latentoutput and run the full schedule - denoise 1, first sigma 1.0. That latent is empty. Starting lower gives you jumbled, collage-looking results. - Connect
sourceand the decoded result to Qwen Edit Align Composite, withmaskasedit_mask. The outline sits just outside the mask, so the composite also restores those pixels from the cleansource. Keep that node'sgrow_pxandfeather_pxat or belowline_px, or you'll paste outline colour back into the frame.
Things that bite:
- You forgot to paint. The guide output is just your image, but the
promptstill says "the area inside the red outline," and the model then hunts for an outline that doesn't exist. - No image connected and none in the editor - the node errors and tells you to open or drop one. Painting travels with the workflow, but the source image lives in
ComfyUI/input/wepenerd_paint_mask; move machines and you copy that folder too, or the reference goes missing. - A connected IMAGE batch gets the same mask on every image, and Qwen reads only the first reference image per slot. Per-image masks aren't a thing here.
solidguide mode on a face. You hid the evidence. Nothing makes the model keep features it can't see.- Editor won't render after an update. Stale JS - hard refresh, and check you're not on an ancient frontend.
One honest note on scope: this gets you region guidance and an exact composite. It doesn't turn Qwen into a masked inpainting model. Unmasked pixels are preserved after the fact, by compositing, not by the sampler.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_data | STRING | — | |
| guide | COMBO | outline | How the painted region is shown to the model. outline draws a ring around it, tint overlays it, solid paints over it (the model cannot see what was there), none leaves the image clean for use with mask_image. |
| color | COMBO | red | Guide colour. Pick one that does not occur in the region. |
| fill_holes | BOOLEAN | true | Treat areas enclosed by paint as part of the region, so a quick loop drawn around an object selects the whole object. |
| line_px | INT | 61–64 | Outline thickness in output pixels. |
| resolution | INT | 10240–4096 | Same rule as Text Encode Qwen Image 2.1: about resolution × resolution pixels in multiples of 32, keeping the aspect ratio. 0 keeps the image size rounded to 32. Set the encoder's resolution to 0 to avoid a second resize. |
| instruction | STRING | What should happen in the painted region, e.g. 'replace it with a red umbrella'. | |
| imageopt | IMAGE | Image to edit. Load input previews the first image for painting. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | Source with the guide drawn in; connect to image_1. |
| source | IMAGE | Clean source at the same size; use for compositing the result back. |
| mask | MASK | Painted coverage at the output size (white = edit). |
| mask_image | IMAGE | Mask as a black/white IMAGE, for the 'none' guide as image_2. |
| prompt | STRING | Your instruction wrapped with a description of the guide. |