Prune By Mask
Drop the images a mask says are empty
- image
- mask
- IMAGE
Prune By Mask filters a batch of images down to only the ones a corresponding mask says actually contain something. Feed it a batch of images and a batch of matching masks, and it drops any image whose mask averages out to less than 0.5 - keeping only the ones where "more than half masked" holds true.
This is the node behind one of the cleverer tricks in the pack's own README: filtering images (or changing where they get saved) based on whether they contain a certain object or concept, without stuffing that concept into a negative prompt and dealing with the side effects of that. The pattern is: generate a batch, run Mask By Text on each image asking "does this contain X", then prune the batch down to only the images where it does (or doesn't, if you invert the mask first). It's a text-prompted filter built out of parts rather than a single specialized node - mask, threshold, prune.
The inputs that matter
- image - the batch of images to filter.
- mask - the batch of masks determining which images survive. Needs to line up one-to-one with the image batch.
The single output is the pruned batch - only images whose associated mask averaged above 0.5 make it through.
Worth being clear about the threshold: it's not "any white pixels," it's "the mask's average value across the whole image exceeds 0.5." A mask that's mostly black with one small white corner won't clear that bar; a mask that's roughly half-and-half is right on the edge. If you need a different cutoff, threshold your mask more aggressively before this node (Combine Masks with round_result, or Mask By Text's own precision) so the average lands cleanly on one side or the other.
Installing it
Prune By Mask is part of Masquerade Nodes. Install via ComfyUI Manager (search "Masquerade Nodes") or manually: cd ComfyUI/custom_nodes && git clone https://github.com/BadCafeCode/masquerade-nodes-comfyui, then restart ComfyUI. No models or extra pip packages of its own.
Common issues
The most common surprise is running this node on a batch size of one and getting confused when "nothing seems to happen" either way - the pack's own docs are explicit that this node is only meaningful with batch sizes greater than one; on a single image it just passes through or drops entirely, which isn't a very useful signal on its own. The other thing to check is alignment: image and mask need to be the same batch size and in the same order, since this node pairs them positionally rather than matching them any smarter way. If your prune result looks arbitrary rather than tied to actual content, verify the mask batch wasn't accidentally built or reordered independently of the image batch somewhere upstream.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |