SEGS Filter
Keep only the SEGS you actually care about
- segs
- filtered_segs
A SAM or YOLO pass on a busy image returns a pile of segments - people, objects, noise. Most of the time you don't want all of them, and that's where XJSegsFilter comes in. It's a small node from the ComfyUI-XJNodes pack that filters a SEGS stream by area, width, height, confidence, or by keeping just the top or bottom N segments.
If you've used Impact Pack, you already know SEGS - it's the packed segment format that travels between detection, cropping, and refinement nodes. This filter speaks that format natively, which means it plugs straight into Impact-style detailer pipelines: detect everything, throw out the tiny detections, and only run your expensive detailer pass on the segments worth refining. It doesn't generate anything itself; it's a gatekeeper sitting between a detector and the rest of the graph.
How it works
The node reads the SEGS list, applies one of six modes, and rebuilds a SEGS object from whatever survived. The comparison modes are all "keep segments at or above threshold":
by_area- pixel area of the crop region (width × height).by_width/by_height- dimensions of the crop box.by_confidence- the detector's confidence score.
The other two flip the meaning of threshold entirely: top_n and bottom_n treat it as a count (n = int(threshold)) and keep the N best or worst segments by confidence. The optional order input (ascending/descending, default descending) only affects the top/bottom modes - it decides which end of the confidence ranking you count from.
Because it returns a proper SEGS (not just a list), everything downstream that accepts SEGS - Impact Pack's detailers, stitchers, mask converters - keeps working unchanged. One input to remember: segs (SEGS), plus mode, threshold, and optionally order. Output is filtered_segs (SEGS).
Installing it
It's part of ComfyUI-XJNodes:
cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes
then restart ComfyUI (or install via ComfyUI Manager, searching ComfyUI-XJNodes). No models, no dependencies beyond stock ComfyUI - though note the SEGS format itself comes from Impact Pack, so if you have no Impact-style nodes to produce SEGS in the first place, this node has nothing to eat.
Common issues
The top/bottom confusion is the thing that trips people: threshold is a minimum for the by-* modes but an exact count for top_n/bottom_n. Feed top_n a threshold of 3 and you keep exactly three segments, not "everything above 3." Also remember that the comparison modes work on the crop region dimensions, not the visual extent of the mask - a segment whose crop box is huge but whose actual object is small still qualifies by area. It's a personal-pack node with no real community behind it, so if the filtering surprises you, the source in nodes/segs/filter.py is short and readable.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | — | |
| mode | COMBO | 6 options: by_area, by_width, by_height, by_confidence, top_n, bottom_n | |
| threshold | FLOAT | 0.00–10000 | — |
| orderopt | COMBO | descending | 2 options: ascending, descending |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| filtered_segs | SEGS | — |