Nodes/WAS Node Suite v3/Mask Dominant Region
ComfyUI Node Runs on cloud

Mask Dominant Region

Keep only the largest blob in a messy mask

By WASasquatch·Created 4 years ago·Updated about 13 hours ago· 1,880
Mask Dominant Region
  • masks
  • MASKS
◄threshold128►
◄drawn_mask►
◄drawn_combineunion►

Segmentation masks are rarely as clean as you want them. Run SAM, or threshold a color, or auto-generate a mask from a detection model, and you'll often get your intended subject plus a scatter of tiny stray white specks elsewhere in the image - noise the underlying method picked up that has nothing to do with what you actually meant to select. Mask Dominant Region cleans that up in one step: it finds every separate white region in the mask and keeps only the largest one, discarding the rest.

Per the README's own description, it "returns the dominant region in a mask (the largest area)." It has a mirror-image sibling, Mask Minority Region, which does the opposite - keeps the smallest region instead, for when the noise is actually what you want and the big blob is what you're discarding.

How it works

It identifies connected regions of white pixels in the input mask - separate, non-touching blobs count as separate regions - measures each one's area, and outputs a new mask containing only the biggest one, with everything else zeroed out. It doesn't reshape or smooth the surviving region, it just removes the competition; if you also want the edges cleaned up, that's a job for Mask Smooth Region or Mask Gaussian Region run afterward, not something this node does itself.

What it takes and gives back

Straightforward mask-in, mask-out: a MASK goes in, and a MASK containing just the dominant region comes out, ready to drop into whatever was going to consume the original mask - an inpaint step, a crop node, a blend. WAS also has a paired Mask Crop Dominant Region node if what you actually want is a tight crop around that largest region rather than a full-size mask with everything else blacked out.

Where it's genuinely useful

Cleaning up a noisy auto-generated mask before it goes anywhere important - SAM output with a few stray pixels flagged elsewhere in frame, a color-threshold mask that picked up a background element sharing a similar hue, anything where "the one big region I actually want" is buried in smaller junk you didn't ask for.

How to install it

ComfyUI Manager: search "WAS Node Suite," install, restart. Manual:

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

then, from inside that folder, install requirements - path/to/ComfyUI/python_embeded/python.exe -s -m pip install -r requirements.txt on portable, pip install -r requirements.txt on system Python. Restart ComfyUI; it's under WAS Suite.

Common issues & troubleshooting

If the output mask is empty or unexpected, the usual cause is that the input mask genuinely doesn't have a clear dominant region - two blobs of nearly identical size, or the mask is mostly noise with no strong single subject - rather than a fault in the node. Preview the input mask first if the result looks off; it's usually telling you something true about the source mask you didn't notice.

This is a simple morphological operation with no external dependency, so it's unlikely to break on its own. The risk that does apply is pack-wide: WAS Node Suite has had no active development since December 2023, and the recurring complaint since then is the entire suite failing to import after a ComfyUI update - a shared-dependency version clash, not anything specific to this node. If it happens, reinstall requirements with your embedded Python interpreter, not a system one.

CategoryWAS Suite/Image/Masking

Inputs (4)

NameTypeDefaultDescription
masksMASKThe mask to subtract a region from. A batch is handled one mask at a time, each losing its own largest unset region.
thresholdINT1280–255Brightness cut-off, 0 to 255: a pixel joins the search when its level is below 255 minus this. 128 = everything dimmer than 127; higher takes in less of the unset area.
drawn_maskoptSTRINGThe mask painted on the node, saved with the workflow. Empty = nothing painted, so the node gives the region mask alone. Run the node once to get a mask to paint on; clear the field to remove the painting.
drawn_combineoptCOMBOunionHow the painting joins the mask this node produced, resized to it if they differ. `union` = the brighter of the two at each pixel; `subtract` = the painting taken away; `intersect` = the darker; `off` = ignored, not deleted.

Outputs (1)

NameTypeDescription
MASKSMASKEverything outside the largest connected unset region is set, as hard black and white: an unset area in one piece comes back as it was, a broken one keeps only its largest piece. Anything painted on the node is joined in.