Nodes/comfyui_gr85/Filter And Combine Masks
ComfyUI Node

Filter And Combine Masks

Drop the tiny detections, keep the rest

By veighnsche·Created 2 years ago·Updated 8 months ago· 1
Filter And Combine Masks
  • masks
  • MASK
threshold_percentage50.0

Run any detector - SAM, GroundingDINO, Florence-2's grounding task - over an image and you'll usually get back more than one mask: a batch, one per detected region. Some of those are exactly what you wanted; others are noise-level detections, a sliver of pixels the detector wasn't confident about but flagged anyway. Filter And Combine Masks does the cleanup step: drop anything under a size threshold, then merge whatever survives into a single mask.

The mechanism. masks takes a batch of MASK tensors - the plural in the input name matters, this node is built to operate on multiple detections at once, not a single mask. threshold_percentage (default 50, range 0–100) sets the cutoff: masks whose area falls below that percentage get filtered out before the merge, so a stray one-pixel detection doesn't survive into your final combined mask. What's left after filtering gets unioned together into one MASK output.

Where it fits. This is the natural next step after any detector that returns multiple regions and before whatever consumes a single mask - inpainting, a detail pass, a mask-based composite. It's a cleanup stage, not a detector itself: it doesn't find anything, it just decides what to keep from what something else already found. That's a smaller job than a lot of mask nodes take on, but it's a genuinely common gap - detectors are tuned to be generous about what they flag (better to catch a marginal region than miss a real one), which means the raw output usually needs exactly this kind of trim before it's usable.

Installing it. Search "comfyui_gr85" in ComfyUI Manager, or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/veighnsche/comfyui_gr85

Restart ComfyUI afterward. No model downloads, no heavy dependencies - it's tensor math on masks you've already generated elsewhere.

Where to watch yourself. The threshold_percentage is relative - 50% of what, exactly, matters a lot, and the schema doesn't spell out whether that's relative to the largest mask in the batch, the total canvas area, or something else. If you set it and get an empty combined mask back, you've probably set the threshold too aggressive for the actual size of your detections; drop it toward 0 and preview the result to find where real detections start surviving. And because this node combines everything that passes the filter into one mask, it's not the right tool if you need to keep detected regions separate for individual processing - for that you want to work with each mask in the batch before it reaches this node, not after. Pair it with GR85_RandomizedMaskTransform from the same pack if the combined mask needs a little jitter afterward, or feed it straight into an inpaint or detail-pass node once you're confident the threshold is dialed in for your typical detection sizes.

CategoryGR85/Mask

Inputs (2)

NameTypeDefaultDescription
masksMASK
threshold_percentageFLOAT50.00–100

Outputs (1)

NameTypeDescription
MASKMASK