SEGS Filter (ordered)
Rank detections by size and keep the top N
- segs
- filtered_SEGS
- remained_SEGS
Your detector found seven faces and you only care about the biggest one. SEGS Filter (ordered) is how you say that. It sorts a SEGS by whatever metric you pick - area, width, height, position, confidence - and hands you a slice of the ranking. "Give me the single largest detection," or "the two closest to the top of the frame," or "everything except the biggest three." It's a small utility, but once you're detailing images with multiple detections it saves you from re-rendering regions you don't want touched.
How it works
It ranks every SEG in the incoming SEGS by your chosen target, in ascending or descending order, then takes a window defined by a start index and a count. Everything inside the window goes out one socket; everything else goes out the other. Nothing is generated or modified - it's pure selection, so it's cheap and instant.
The distinction from its sibling, SEGS Filter (range), is worth getting straight: ordered works by rank ("the top 2 by size"), range works by absolute value ("everything wider than 100px"). Reach for ordered when you care about which are biggest/smallest relative to each other; reach for range when you have a hard threshold.
The inputs and outputs that matter
segs(SEGS) - the detections to sort.target- what to rank by. Options includearea(=w*h)(the common choice),width,height, the box coordinatesx1/y1/x2/y2(rank by position),confidence, andnone.order(default on) - the sort direction. This flips whether "take the first" means largest or smallest, so check it if you're getting the opposite of what you wanted.take_start(default 0) - where in the ranking to start. 0 is the top.take_count(default 1) - how many to take. Default 1 gives you the single top-ranked SEG.
Two outputs: filtered_SEGS (the ones you selected) and remained_SEGS (everything else). That second output is genuinely useful - you can detail the biggest face one way and pass the rest to a different detailer, or just discard them.
How to install it
Ships with the pack. ComfyUI Manager: search ComfyUI Impact Pack, Install, restart.
Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack
cd ComfyUI-Impact-Pack
pip install -r requirements.txt
Run the pip step in ComfyUI's own Python environment and restart. No extra models needed for this node - it only shuffles SEGS around.
Common issues & troubleshooting
You got the smallest when you wanted the largest. Flip order. The sort direction is the single most common mix-up here, and there's no shame in toggling it and re-running to see which way is which.
Empty output. If take_start is past the end of the ranking, the window is empty. With three detections, take_start: 5 gives you nothing. Keep the start within the number of SEGs you actually have.
You wanted a threshold, not a rank. If your rule is "faces bigger than X pixels" rather than "the N biggest faces," this is the wrong node - use SEGS Filter (range) instead, which filters by absolute value with a min and max.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | — | |
| target | COMBO | 9 options: area(=w*h), width, height, x1, y1, x2, +3 | |
| order | BOOLEAN | true | — |
| take_start | INT | 00–9223372036854776000 | — |
| take_count | INT | 10–9223372036854776000 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| filtered_SEGS | SEGS | — |
| remained_SEGS | SEGS | — |