Nodes/WAS Node Suite v3/Mask Guided Filter
ComfyUI Node Runs on cloud

Mask Guided Filter

Make a sloppy mask actually hug the subject

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Mask Guided Filter
  • masks
  • image
  • masks
radius12
epsilon0.0001

Mask Guided Filter refines a mask against the image it belongs to, so the mask's edge stops sitting vaguely beside the subject and actually follows the subject's outline. Give it a rough selection - a CLIPSeg blob, a boxy SAM result, a hand-painted mask that overshot by a few pixels - and the image it was made for, and it pulls the mask's boundary onto the image's own edges. Where a grow or feather only nudges a mask's shape, this one uses the image's content to decide where the true edge is.

It's a WAS Node Suite mask node (WAS Suite/Image/Masking), and it runs on ComfyUI's own device with no extra packages - part of the v3 rewrite's rule that the pack installs nothing.

How it works

Two required inputs: masks (the mask to refine) and image (the picture the mask belongs to). The image is the guide - its edges, color included, are what the mask gets pulled onto. Two knobs control how that happens:

  • radius (default 12) - how far, in pixels, the mask may travel to find the image's edge. The tooltip puts it best: it's roughly how wrong the mask's edge is. A selection that's 5 pixels off the subject gets a radius around 5–10; something looser needs a bigger radius.
  • epsilon (default 0.0001) - how closely the mask follows the image. Small values like 0.0001 snap hard onto every edge; larger values like 0.01 leave a softer edge that ignores texture. When your subject has noisy detail you don't want the mask chasing, raise epsilon rather than fighting the result.

Two behaviors make it friendlier than a typical matting node. If the mask is smaller than the image, it's lifted to the image's size first - so a low-resolution mask can be used as-is and the output still lines up. And the output masks comes back at the image's size, ready to wire into a crop, a paste, or an inpaint that expects aligned geometry.

Why you'd reach for it

Three jobs, in rough order of how often people hit them:

  1. Tidy a rough selection. Detector masks are rarely pixel-perfect. A CLIPSeg mask that includes background between a person's arm and torso, or a SAM mask that swallows a bit of sky, gets pulled back onto the actual silhouette.
  2. Soften a hard cut-out naturally. Instead of feathering a brutal edge into a soft blur (which fakes it), let the image's own boundary define the falloff - the result looks like a matte instead of a sticker.
  3. Up-sample a small mask. Bring a low-detail or low-res mask up to the image's size and let the filter fill in the boundaries using the image's own edges, rather than a blocky nearest-neighbor resize.

In the detailer vocabulary from the KB ("zoom in on a mask, upscale, re-render, paste back"), this is the node that makes step four invisible - the composite only looks clean if the mask edge matches the subject.

Installing it

Part of WAS Node Suite v3 - ComfyUI Manager search "WAS Node Suite v3", or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

restart. ComfyUI 0.14.0+ and Python 3.10+; nothing to pip-install.

Where people get burned

The usual failure is radius too small for how wrong the mask is - the filter then can't reach the true edge and you get a mask that looks "tightened" but still misses. Estimate the offset honestly and set radius past it. The second failure is epsilon too small on a textured background, which makes the mask chase leaves and grass and come back noisy; bump epsilon when the image is busy. And a guided filter needs a guide: if the subject and background are nearly the same tone at the boundary, there's no edge for the mask to find, and no radius setting fixes that - feathering or manual touch-up is the honest fallback.

CategoryWAS Suite/Image/Masking

Inputs (4)

NameTypeDefaultDescription
masksMASKThe mask to refine; MASK. Smaller than the image, it is lifted to the image's size first, so a low-resolution mask can be used as it is.
imageIMAGEThe picture the mask belongs to; IMAGE. Its edges are the ones the mask is pulled onto, colour included.
radiusINT121–256How far the mask may move to find the image's edge, in pixels; INT. Costs the same at any size. Roughly how wrong the mask's edge is.
epsilonFLOAT0.00010–1How closely the mask follows the image; FLOAT. Small values such as 0.0001 snap hard to every edge, larger ones such as 0.01 leave a softer edge that ignores texture.

Outputs (1)

NameTypeDescription
masksMASKThe refined mask; MASK, at the image's size.