BD Parts Builder
From segmented masks to per-part crops — BD Parts Builder
- image
- sapiens2_labels
- masks
- depth_image
- combined_mask
- image_batch
- label_list
- bbox_list
- parts
Segmentation gives you a pile of masks; a character parts pipeline needs parts - each region cropped into its own image with a bbox, a tag, and a place in the stack. BD Parts Builder is the node that makes that jump. You feed it masks (SAM3 per-prompt masks or Sapiens2 labels) plus the source image, and it emits a PARTS_BUNDLE where every part has its own RGBA crop, bounding box, and label, ready for the pipeline's next stages: refine already happened upstream, batch-edit and underpaint run next, export finishes.
Two input styles, and the README is explicit about which to prefer: sapiens2_labels (from a Sapiens2 segmentation node, carrying its class taxonomy) or the generic masks + mask_labels pair (e.g. SAM3 Multi-Prompt output). When sapiens2_labels is wired, masks/mask_labels are ignored. A selection_mode preset lets you filter: all (everything but Background), clothing/bodyparts (curated Sapiens2-taxonomy subsets), or specific with your own selection_list. Note the presets only understand Sapiens2's 29 classes - for SAM3 sources, use all or specific.
Inputs that shape the parts
padding_pixels(default 5) - breathing room around each bbox, in source resolution. Give a little padding; it saves you from razor-thin crops.output_size-nativekeeps each crop's natural size; 512/1024/2048 scales the longest side.square_pad-pad_to_squarecenters each crop on a square canvas (uniform aspect, ideal for upscaler batching and T3D);nonekeeps aspect.background-alpha(default) bakes the mask into the RGBA alpha channel; white/black/hex composites onto a solid.min_pixels(default 64) - drops parts below this mask area.
The optional combined_mask is important: wire SAM3's combined_mask (the authoritative silhouette after negatives/vote/color filter) and every part gets intersected with it before cropping - so the "noise SAM3 already ruled out" never makes it into a part. The tooltip's warning is worth repeating: don't wire an inverted mask here, or you'll silhouette the background and zero out every real part.
Wire depth_image (e.g. BD Lotus2 Predict's raw_linear, 0=near 1=far) and each part gets a depth_median - the median depth within its mask - which the compose/export stages use for back-to-front sorting. That's the field that makes the final composite stack in the right order.
Outputs
parts- thePARTS_BUNDLE, the pipeline's primary output.image_batch- the crops as one IMAGE batch, for batch-only workflows likeBD Bulk Saveor upscaling.label_list,bbox_list- parallel strings for those batch paths.
Install
In ComfyUI-BrainDead: Manager search "BrainDead", or clone + pip install -r requirements.txt, restart. Under 🧠BrainDead/Segmentation; V3-API pack, so update ComfyUI if nodes don't show.
The failure modes are mostly upstream: if your parts are mislabeled, the problem is usually the mask/label alignment (labels must be parallel to the mask batch, one per line), and if every part comes out empty, check the combined_mask isn't inverted. This is also where the pack's SAM3 node earns its keep - BD SAM3 Multi-Prompt produces aligned per_prompt_masks + labels in one node, which is exactly the shape Parts Builder expects. Feed it that, wire combined_mask and depth_image, and the parts are ready for the heavy lifting.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| selection_mode | COMBO | all | all = every class except Background. clothing/bodyparts = curated subsets (Sapiens2 taxonomy). specific = whitelist from selection_list. |
| padding_pixels | INT | 50–512 | Pixels of padding around each part's bbox (in source resolution). |
| output_size | COMBO | native | native = keep crop's natural size (per-part may differ — batched by padding to common max). 512/1024/2048 = scale longest side, preserve aspect. |
| square_pad | COMBO | pad_to_square | pad_to_square: center each crop in NxN canvas (uniform aspect, ideal for upscaler batching and T3D). none: keep aspect, pad batch to the rectangular common-bbox of all crops. |
| background | COMBO | alpha | alpha = RGBA, mask baked to alpha channel (best for T3D). white/black/hex = composite onto solid background (best for 2D pipeline). |
| min_pixels | INT | 641–10000000 | Drop parts whose mask area is fewer than this many pixels. |
| sapiens2_labelsopt | SAPIENS2_LABELS | Preferred input from Sapiens2Segmentation. Carries class_ids tensor + part name taxonomy. When wired, `masks` and `mask_labels` are ignored. | |
| masksopt | MASK | Generic MASK batch (B,H,W) — one mask per class. Used when sapiens2_labels is not wired (e.g. SAM3 multi-prompt output). | |
| mask_labelsopt | STRING | Parallel labels for `masks` (newline or comma separated). Auto-named part_00, part_01, … if shorter than the batch. | |
| depth_imageopt | IMAGE | Optional depth IMAGE (e.g. from BD_Lotus2Predict.raw_linear). When wired, each part's depth_median is computed from the median depth value within its mask region (used by Composite for back-to-front sort), AND the cropped depth map for that part is stored in the parts dict so Export can save it. Use the raw_linear output (0=near, 1=far) for proper sorting. | |
| combined_maskopt | MASK | Optional silhouette mask. When wired, every per-class/per-prompt mask is intersected with this before bbox + crop. Sources: • BD_SAM3MultiPrompt.combined_mask — drops pixels removed by negatives / vote / color filter. The authoritative final layer. • Sapiens2SegmentationAdvanced.foreground_mask — confines per-class to body. WARNING: do NOT wire an inverted mask here. If SAM3's invert_combined=True is set upstream, you'll get the BACKGROUND silhouette — every real part will be zeroed and you'll see only a single full-image leftover. | |
| selection_listopt | STRING | When selection_mode=specific: comma or newline separated label names to include (e.g. 'Left_Shoe,Right_Shoe,Upper_Clothing'). | |
| output_size_customopt | INT | 102464–8192 | Used when output_size=custom. |
| background_hexopt | STRING | #888888 | Hex color when background=hex. Accepts #RGB or #RRGGBB. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image_batch | IMAGE | — |
| label_list | STRING | — |
| bbox_list | STRING | — |
| parts | PARTS_BUNDLE | — |