Nodes/was-node-suite-comfyui/Mask Dominant Region
ComfyUI Node Runs on cloud

Mask Dominant Region

Keep only the largest blob in a messy mask

By WASasquatch·Created 3 years ago·Updated 2 days ago· 1,839
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 on a 0-255 scale. The mask is inverted before the regions are found, so a pixel joins the search when its own level is below 255 minus this value: at the default 128 that is everything dimmer than 127, and a higher value takes in less of the mask's unset area.
drawn_maskoptSTRINGThe mask painted on the node, written by the interface and saved with the workflow. Empty means nothing was painted, and the node then produces the region mask alone. The node has to have run once before there is a mask to paint on. Clear the field to remove the painting.
drawn_combineoptCOMBOunionHow the painting joins the mask this node produced. union keeps whichever of the two is brighter at each pixel, subtract takes the painting away from the mask, intersect keeps whichever is darker, and off ignores the painting without deleting it. The painting is resized to the mask when the two differ.

Outputs (1)

NameTypeDescription
MASKSMASKEverything outside the largest connected region of the input's unset area, as hard black and white with no grey levels left. On a mask whose unset area is one connected region that is the input mask itself; where it is broken into pieces, all but the largest come back set. Anything painted on the node is joined in.