Pixelwise(SEGS & MASK)
Intersect a detection batch with a precise mask
- segs
- mask
- SEGS
This is the node behind one of the pack's own worked examples, and it's worth leading with because it explains the whole point better than the abstract description does. Detect a face with a bounding-box detector and you get a rectangle - includes some hair, some neck, maybe a shoulder. Run SAM on that same region and you get a precise silhouette - just the face, pixel-accurate. AND those two together and you get a mask that only covers the actual face, not the rectangle around it. That's what this node does: a pixelwise AND between a SEGS collection and a single MASK, keeping only the overlap.
Why this matters for detail passes
A bounding box is a rectangle; a face isn't. If you run a Detailer straight off a bbox detection, the refined patch it pastes back covers the whole rectangle - background, hair, collar, whatever else got swept in - and any of that not-actually-face content gets resampled too, which can introduce artifacts or just subtly change things you didn't want touched. Tightening the SEGS mask down to the true subject silhouette before detailing means the pass only touches what it should. This node is the tightening step: combine a rough-but-reliable detector's SEGS with a precise-but-separate silhouette mask (commonly from SAM), and what comes out only covers where both agree.
The inputs and output
segs(SEGS) - the detection collection whose masks you're intersecting.mask(MASK) - a single mask to AND against every element in that SEGS collection.
Output is a single SEGS, same elements, tighter masks.
One distinction worth knowing before you go looking further: this applies one mask across the whole SEGS collection. If you need a different mask per individual detected element instead of the same mask for all of them, that's a separate node - the pack's ForEach variant handles a batch of masks matched up element-by-element. This one is for the simpler, and much more common, case of a single external mask.
Installing it
Standard install, no extra dependency for this node specifically. Via ComfyUI Manager: search ComfyUI Impact Pack, Install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack
cd ComfyUI-Impact-Pack
pip install -r requirements.txt
(portable: python_embeded\python.exe -m pip install -r requirements.txt), restart. This node itself needs no models - but the realistic workflow around it (bbox detector + SAM detector) does need detector and SAM model weights loaded via SAMLoader (Impact) and whichever bbox/SEGM detector provider you're using. Check those are set up before assuming this node is the thing not working.
Common issues
If the output mask ends up looking oddly small or empty, the most common cause is the two inputs disagreeing about where the subject actually is - a loose bbox detection ANDed against a precise, differently-positioned SAM mask can leave you with very little actual overlap if the two detections aren't well aligned. Preview both inputs separately (SEGSPreview for the SEGS, a mask preview for the MASK) before combining them if the result looks wrong, rather than assuming this node mishandled the intersection - a pixelwise AND does exactly what it says, so a thin result usually means the inputs themselves barely agree.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | — | |
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SEGS | SEGS | — |