PD:Select_Mask
Select_Mask: keep only the biggest (or smallest) blob in your mask
- image
- filtered_image
- filtered_mask
- filtered_mask_image
PD:Select_Mask (mask_edge_selector) looks at a mask, finds every separate "blob" in it, and keeps only one - the largest, or the smallest, your choice. It's a filter, not a mask generator. If your mask came out speckled with stray noise or a subject is broken into disconnected pieces, this node collapses the mess into a single clean region.
How it works
The implementation is textbook connected-component analysis. It takes the dark/transparent parts of the input (alpha == 0 for RGBA, or brightness == 0 for RGB) as the "foreground" regions, labels each connected component, and measures their areas. In max mode it keeps the biggest blob; in min mode the smallest. Everything else is zeroed out. The three outputs are the payoff:
filtered_image- the input pixels but with only the chosen component's region intact.filtered_mask- just that component as a mask.filtered_mask_image- the same mask visualized as an image, which saves you a Convert Mask to Image step when you want to actually look at it.
When you'd reach for it
Mostly cleanup. Detectors and auto-maskers are sloppy - a background-removal result or an edge mask often has little islands of noise that pollute downstream steps. max mode is the "keep the main subject, drop the confetti" button. min mode is rarer but genuinely useful in the reverse case: keep the small specks and drop the big region, which is the move when the big area is the background you're trying to exclude.
Inputs
Just two: image and mode (max or min, default max). That's the whole surface. No threshold knob, no min-area - if a component is connected to another by even one pixel, it counts as one blob, so a barely-touching artifact can merge two regions into one. Worth knowing before you blame the node.
Installing
Part of the 7BEII/Comfyui_PDuse pack. ComfyUI Manager → search "Comfyui_PDuse" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt
Restart after. No models; dependencies are Pillow, numpy, scipy (for the labeling), opencv-python and friends.
Gotchas
The mask semantics are worth double-checking: this node treats dark = foreground, which is the inverse of ComfyUI's usual "white = keep" mask convention. Feed it a standard ComfyUI mask where white is the subject and max mode will happily keep the black background instead. If your output looks inverted, flip your mask before it enters. And remember it selects by total pixel area, not by bounding-box size or "importance" - a long thin line has more area than a small square and will win in max mode.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mode | COMBO | max | 2 options: max, min |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| filtered_image | IMAGE | — |
| filtered_mask | MASK | — |
| filtered_mask_image | IMAGE | — |