Nodes/ComfyUI Impact Pack/Pixelwise(SEGS & MASKS ForEach)
ComfyUI Node Runs on cloud

Pixelwise(SEGS & MASKS ForEach)

Intersect each detection with its own mask

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
Pixelwise(SEGS & MASKS ForEach)
  • segs
  • masks
  • SEGS

This is the node that makes detailing follow the shape of a thing instead of its bounding box. It takes a SEGS and a batch of masks, and does a pixelwise AND between each detection and its matching mask - trimming each region's mask down to where the two agree. The headline use: combine a face bounding-box detector with a SAM silhouette, so the detail pass hugs the actual face contour and leaves the background untouched.

Grounding: a SEGS is Impact Pack's detection bundle - one region per hit, each with a box, a mask, a confidence, and a label. A box detector gives you rectangular regions; a segmentation model like SAM gives you precise silhouettes. Each is useful; intersecting them is more useful.

How it works

It's a pixelwise AND performed per element - and the pack is explicit that this runs against a batch of masks, not a single one. So mask N is AND-ed with SEG N: the first detection meets the first mask, the second meets the second, and so on down the batch. The result keeps a region's pixels only where both the SEG's own mask and the supplied mask are set. That's exactly the recipe from Impact Pack's classic combination workflow: detect a face's bounding box, run SAM to get the person's silhouette, then use this node so the intersecting mask precisely follows the face and doesn't bleed into the background when the detailer resamples. The output is a SEGS with tightened masks - same regions, better boundaries.

The inputs and output

  • segs (SEGS, required) - the detected regions whose masks you want to refine.
  • masks (MASK, required) - a batch of masks, one per SEG, AND-ed element-by-element with the SEGS.

Output is a SEGS with each region's mask intersected against its mask. Feed it straight into a detailer, or preview it first to confirm the shapes came out right.

How to install it

Comes with Impact Pack. ComfyUI Manager: search ComfyUI Impact Pack, Install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack

then pip install -r requirements.txt in ComfyUI's Python env (portable build: python_embeded\python.exe -m pip ...), restart. Pack's by ltdrdata, the ComfyUI-Manager author - mainstream and trusted. For the SAM silhouettes this pairs with, the pack auto-downloads a small SAM model to ComfyUI/models/sams on first run; the YOLO box detectors are in the separate Impact Subpack.

Common issues & troubleshooting

The pairing is the thing to get right. This is a ForEach / batch operation, so the mask batch needs to correspond to the SEGS elements - mismatched counts or ordering give you intersections against the wrong masks, and the result looks scrambled. If you only have a single mask to AND against a whole SEGS (not one-per-region), you want the plain SEGS & MASK node instead, not this ForEach version. And if the output masks come back empty, the two inputs didn't overlap where you expected - check that the SAM silhouette and the box detections are on the same image at the same resolution, because an AND of two non-overlapping masks is, correctly, nothing.

CategoryImpactPack/Operation

Inputs (2)

NameTypeDefaultDescription
segsSEGS
masksMASK

Outputs (1)

NameTypeDescription
SEGSSEGS