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 about a year ago· 1,812
Mask Dominant Region

      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.

      Categoryx

      Inputs (0)

      No inputs

      Outputs (0)

      No outputs