๐บ๐ช Largest Mask Only
Largest Mask Only (Bjornulf_custom_nodes) โ ComfyUI Node Guide
- mask
- MASK
This one's a cleanup node, and it solves a specific annoyance: automatic segmentation is noisy. Run something like SAM or a YOLO detector - the kind of thing Impact Pack's detector nodes hand you - over an image and you often don't get one clean mask of your subject. You get your subject plus a scatter of tiny false-positive blobs: a stray reflection, a shadow edge, a piece of background texture that happened to trip the detector. Largest Mask Only exists to throw that noise away and keep only the region(s) that are actually big enough to matter.
How it works
The mechanism is exactly what it sounds like: it looks at the mask you feed it, measures the area of each distinct region, sorts by size, and keeps the top num_masks of them, discarding the rest. Feed it a mask with your subject and eight pixels of speckle noise around it, set num_masks to 1, and you get back just the subject - clean.
It's a small node, but it's the kind of small node that saves you from building the same connected-component filtering logic yourself with a Mask Compositing chain every time a detector hands you something messy.
Inputs and outputs
Two required inputs: mask (the MASK you want to filter), and num_masks, an integer from 1 to 10 (default 1) controlling how many of the largest regions survive. There's no threshold-by-percentage option and no way to keep the smallest regions instead - it's strictly biggest-N, nothing fancier. One MASK output.
Set num_masks to 1 for the common case - isolating a single subject, a single face, a single largest blob from a background-removal or segmentation pass. Bump it higher if you're deliberately keeping multiple regions (say, two people detected in a shot) but still want to drop everything smaller than genuine subjects.
Installing it
Through ComfyUI Manager, search for "Bjornulf_custom_nodes" - that's the pack title, and installing it pulls in this node along with the other 100-plus in the collection. Manual route: cd ComfyUI/custom_nodes && git clone https://github.com/justUmen/Bjornulf_custom_nodes, then restart ComfyUI. No model download and no special dependency for this specific node - it's pure mask arithmetic, so it doesn't pull in anything beyond the pack's base requirements.txt.
One honest note: this node isn't in the pack's own README node index (which documents roughly 170 nodes individually with screenshots). It's newer than that documentation - the pack is under genuinely active, fast-moving development, and new nodes ship ahead of the docs catching up. That's not unusual for this repo specifically; treat the inputs and outputs above as the ground truth rather than looking for a screenshot walkthrough that doesn't exist yet.
Common issues & troubleshooting
The main failure mode is conceptual, not technical: if your upstream mask is already a single clean blob (say, from a well-tuned rembg pass), this node does nothing useful - there's nothing to filter. It earns its keep specifically after multi-region, noisy segmentation, so if you're not seeing a difference, check whether your input mask actually has multiple disconnected regions in the first place.
If you're chaining this after Impact Pack's SAM or BBOX detector output, remember those nodes typically return SEGS, not a raw MASK - you'll need to convert SEGS to a mask batch first (Impact Pack has nodes for exactly that) before this node has something to work on. And because it's purely area-based, a large wrong detection - background misidentified as foreground - will happily survive the filter while your actual subject, if it's smaller, gets dropped. It cleans up size-based noise; it has no concept of what the mask is actually a mask of.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | โ | |
| num_masks | INT | 11โ10 | โ |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | โ |