Nodes/tri3d-comfyui-nodes/Extract Masks Batch v5.1.0
ComfyUI Node

Extract Masks Batch v5.1.0

Turn ATR segmentation maps into the exact masks you need (and only those)

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Extract Masks Batch v5.1.0
  • batch_segs
  • MASK
right_legfalse
right_handtrue
headfalse
hairfalse
left_shoefalse
bagfalse
backgroundfalse
dressfalse
left_legfalse
right_shoefalse
left_handtrue
upper_garmentfalse
lower_garmentfalse
beltfalse
skirtfalse
hatfalse
sunglassesfalse
scarffalse

Once you've run the pack's ATR parse on a batch, you've got 18 classes of body parts and garments sitting in one colored map per image. tri3d-extract-masks-batch is the picker: a wall of booleans, one per ATR class, and it returns a single MASK batch containing exactly the classes you ticked, combined. It's the node you reach for when you need a head mask, a hands mask, a hair mask, or an "everything that's not the garment" mask for an inpainting step.

What it does

One image input - batch_segs, the palette-colored segmentation maps straight from tri3d-atr-parse-batch. Then eighteen booleans, one per class:

  • head, hair, hat, sunglasses, scarf, bag
  • upper_garment, lower_garment, dress, belt, skirt
  • left_hand, right_hand, left_leg, right_leg, left_shoe, right_shoe
  • background

The mechanism is dead simple: for each selected class it does an exact color match against the ATR palette (cv2.inRange on the specific RGB value - [192,128,0] for head, [64,128,128] for left hand, and so on), ORs the results together, and stacks one mask per input image. The defaults are worth noticing: left_hand and right_hand default to True while everything else defaults to False - this pack is aimed at garment try-on, and hands are the usual thing you want to protect from being painted over.

Exact color matching has a real consequence: it only works on this pack's own ATR output. Any JPEG-ish compression artifacts or a different segmenter's palette will produce empty masks. Keep the parse and the mask extraction in one lineage.

Where it fits

This is the masking side of the VTON pipeline: parse → extract masks → use them for inpainting (keeping the garment out of the model's hands), background removal, or composing. If you want actual crops rather than masks, use tri3d-extract-parts-batch instead - it does the same class selection but cuts out the image region around each selected part. This node outputs pure MASK, ready for any mask-typed input: inpaint conditioning, denoise masks, composite, whatever.

Installing

ComfyUI Manager (search "tri3d"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes

Restart and install requirements (pip install -r custom_nodes/tri3d-comfyui-nodes/requirements.txt). No model downloads here - it's pure color-keying.

Troubleshooting

  • Empty mask despite ticking a class - the segmentation colors don't match the palette (different segmenter, re-encoded image, or the parse node failed silently). Re-run the ATR parse and don't convert the maps between steps.
  • Mask includes more than you wanted - remember the classes are OR'd together; untick the ones you don't want. The two hand classes default to on, which surprises people who just want the garment.
  • Shape mismatch downstream - the node pads masks to the max width/height in the batch, so a mixed-size batch produces uniform shapes (that's on purpose, but it can shift positions if you mix resolutions).

It's a menu, not a brain - but for garment workflows, a menu that outputs exactly the masks you asked for is worth its weight in reruns.

CategoryTRI3D

Inputs (19)

NameTypeDefaultDescription
batch_segsIMAGE
right_legBOOLEANfalse
right_handBOOLEANtrue
headBOOLEANfalse
hairBOOLEANfalse
left_shoeBOOLEANfalse
bagBOOLEANfalse
backgroundBOOLEANfalse
dressBOOLEANfalse
left_legBOOLEANfalse
right_shoeBOOLEANfalse
left_handBOOLEANtrue
upper_garmentBOOLEANfalse
lower_garmentBOOLEANfalse
beltBOOLEANfalse
skirtBOOLEANfalse
hatBOOLEANfalse
sunglassesBOOLEANfalse
scarfBOOLEANfalse

Outputs (1)

NameTypeDescription
MASKMASK