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

Mask Arbitrary Region

Grab the mask blob closest to a size you pick

By WASasquatch·Created 3 years ago·Updated about a year ago· 1,812
Mask Arbitrary Region

      WAS gives you Mask Dominant Region for "keep only the biggest blob" and Mask Minority Region for "keep only the smallest." Most of the time that's the whole spectrum you need. Mask Arbitrary Region exists for the case in between: you don't want the biggest, you don't want the smallest, you want whichever region is closest to a size you specify. Per the README's own wording, it returns "a region that most closely matches the size input (size is not a direct representation of pixels, but approximate)." That parenthetical matters - treat the size you feed it as a relative dial for ranking candidates, not a literal pixel-area contract.

      Why you'd reach for it

      Segmentation and thresholding rarely hand you exactly two regions. Run SAM loosely, or threshold a busy image by color, and you can end up with three, four, half a dozen separate blobs of genuinely different sizes - a big one, a medium one, some small noise. Dominant always grabs the biggest, Minority always grabs the smallest, and neither one lets you say "actually, I want the medium one." Arbitrary Region is the tool for exactly that situation: rank every region by how close its area sits to your target and keep the closest match.

      How it works

      It identifies every separate connected region of white pixels in the mask the same way Dominant and Minority Region do, measures each one's area, and instead of picking the extreme (largest or smallest), it picks whichever region's area comes closest to the size value you gave it. Everything else gets zeroed out, same as its siblings - the difference is purely in which candidate wins.

      Because the size input is explicitly approximate rather than a pixel count, don't expect to dial in "exactly this many pixels." Think of it as a rough pointer into the distribution of region sizes present in your specific mask.

      The inputs and outputs that matter

      A MASK in, an approximate target size to rank candidates against, and a MASK out containing only the region that best matched. If your mask genuinely only has two meaningfully different region sizes, Arbitrary Region will just land on whichever one is closer - at that point it behaves like a slightly indirect way of picking Dominant or Minority, so it earns its keep most clearly on masks with three or more distinct blobs.

      Installing it

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

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

      then install requirements.txt against your ComfyUI Python - python_embeded\python.exe -s -m pip install -r requirements.txt on a portable build - and restart. No model download, it's morphology on a tensor.

      Common issues & troubleshooting

      It keeps picking the same region as Dominant or Minority. Check how many genuinely distinct-sized regions your input mask actually has. A mask with one big region and one tiny speck only gives Arbitrary Region two things to choose between, so unless your target size sits right in the middle, it'll converge on whichever extreme is closer - which isn't a bug, it's the mask not having a real "medium" candidate to offer.

      Nothing comes back, or the wrong blob wins. Preview the input mask before assuming the node is broken. "Approximate" ranking on a noisy mask with lots of similarly-sized fragments can pick a candidate you didn't expect; cleaning the mask first (a threshold pass, Mask Fill Holes for interior gaps) usually sharpens which region actually wins.

      The whole pack disappeared. That's WAS Node Suite as a whole, not this node - it's been unmaintained since the author marked it retired in December 2023, and the well-known failure mode is the entire suite throwing "Import Failed" after a ComfyUI update because a shared pinned dependency got bumped underneath it. Reinstall requirements.txt against the correct (embedded, not system) Python interpreter and restart.

      Categoryx

      Inputs (0)

      No inputs

      Outputs (0)

      No outputs