Nodes/ComfyUI-lhyNodes/WanAnimate Mask Preprocessor
ComfyUI Node

WanAnimate Mask Preprocessor

Wan Animate masking is fiddly — this node is the cleanup step

By lihaoyun6·Created 12 months ago·Updated 13 days ago· 20
WanAnimate Mask Preprocessor
  • image
  • mask
  • image
  • mask
expand_by10
tapered_cornerstrue
block_size32
color0, 0, 0
batch_size5
devicegpu

If you've painted a mask for Wan Animate, you know the drill: ten minutes clicking points, the mask grabs half the frame anyway, and the model does something you didn't ask for. The "Wan Animate masking help" threads write themselves. This node is the cleanup step that lives between the mask you drew and the mask the model actually conditions on.

Wan Animate (Wan 2.2's Animate-14B) takes a reference image plus a mask that marks the region the model should treat as special - typically the character you want to keep while the rest of the frame regenerates to match the driving motion. Raw masks are never ready for that. They're too tight around the subject, they grow boxy corners where the expansion leaked, they have ragged edges, and they sit at a resolution that doesn't match what the model reads. All three of those problems are this node's job.

How it works

It's all tensor math, no model, nothing to download. The mask is resized to match the reference if the sizes disagree, then expanded or eroded - expand_by is a plain dilation: positive grows the mask, negative shrinks it. If tapered_corners is on (it is by default), the expansion uses a diamond kernel instead of a square one, so you don't get blocky corners on your subject. Then, if block_size is above zero, the mask is quantized into a coarse grid and upscaled back - a deliberate match for the coarse mask resolution the model conditions on. Finally it composites a flat fill color over the masked region of the reference. You get both halves back: the recolored reference and the processed mask.

Inputs and outputs

  • expand_by (default 10): start here. If the model keeps chopping your character's edges, bump it up; if the fill is bleeding onto the subject, dial it down or go negative to erode.
  • block_size (default 32): the blockify switch. Set to 0 to turn it off and keep a smooth mask.
  • color (default "0, 0, 0"): the flat fill. Accepts "r, g, b" or "#rrggbb", and a fourth channel adds alpha.

batch_size and device are performance knobs; device quietly falls back to CPU if CUDA isn't available. Outputs are image and mask, both wired onward into your Animate workflow - the pack's own Mask to Coordinates V2 exists to turn these into positive/negative SAM conditions if you want finer control than a brush gives you.

One thing that trips everyone up: polarity. This node fills whatever your mask marks with the flat color; whatever's outside the mask is preserved from the reference. If you mask the character and the fill lands on it, your mask is inverted - flip it upstream or paint the other region. And the black fill is a convention, not a bug: the model reads the flat region as "regenerate here."

Installing it

Search lhyNodes in ComfyUI-Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/lihaoyun6/ComfyUI-lhyNodes.git
python -m pip install -r ComfyUI-lhyNodes/requirements.txt

Restart, and it's under the lhyNodes/Wan menu. No model files, no extra weights.

Common issues

If color parsing fails, check your string: values over 1.0 are read as 0–255, values under 1.0 as 0–1, and hex is supported. If your mask batch is shorter than your image batch, masks cycle - the index wraps around, which is usually exactly what you want for one mask carried across a whole sequence. And when the fill ends up on the wrong side, that's a mask problem, not a node problem: fix polarity before you start blaming the preprocessor. It won't rescue a bad mask, but it will take a halfway-decent one and turn it into something the model can actually work with.

CategorylhyNodes/Wan

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
maskMASK
expand_byINT10-255–255
tapered_cornersBOOLEANtrue
block_sizeINT320–512
colorSTRING0, 0, 0
batch_sizeINT51–100
deviceCOMBOgpu2 options: cpu, gpu

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK