BD Parts Batch Edit (Qwen)
Redraw every part of a character in one run — BD Parts Batch Edit (Qwen)
- parts
- model
- clip
- vae
- source_image
- parts
- summary
- image_batch
Here's the problem the BrainDead parts pipeline solves: SAM3 segments a character into parts, but the masks only show the visible pixels. The pants under the holster, the shirt under the jacket - those parts are incomplete. To rebuild them you'd normally loop part-by-part through Qwen Image Edit manually, and on a ten-part character that's ten separate babysitting sessions. BD Parts Batch Edit (Qwen) does the whole loop inside one node: every part in a PARTS_BUNDLE gets its own Qwen Image Edit pass in a single execution, and the bundle comes out with every part rebuilt.
The mechanism is worth understanding because it explains the defaults. Each part's RGBA is composited onto neutral gray, and its prompt is built by dropping the part's tag into prompt_template (the default is tuned for low-poly stylized characters: "Recreate the complete {tag} in the same low-poly game style, sharp clean edges, fill any occluded or missing regions..."). The result is encoded, sampled, and decoded with the original alpha reapplied so edges stay clean.
The two modes
flatten_redraw(default) - flattens the part on a white background, encodes it, latent-upscales bylatent_upscale_factor(1.25 default, the high-res-fix trick), samples, tonemaps, and decodes. Produces a clean object render, then cuts it to the part outline so the composite assembles without white backgrounds.true_inpaint- latent-space inpaint with a prefilled source crop; the noise mask covers only enclosed holes, so Qwen regenerates just the missing regions and preserves what's visible. Best for completing obstructed parts. Requiressource_imagewired so Qwen sees full context (pants with the gun on top).
This node is built around the Qwen Image Edit 2509 fp8 stack with the 4-step Lightning LoRA - the defaults match that setup exactly: steps=4, cfg=1.0, sampler=euler, scheduler=simple. It also applies the internal patches (shift=3.0, CFGNorm 0.85, Reinhard tonemap 2.0) that the manual recipe uses. If you're on a different stack, adjust accordingly; model_sampling_shift and cfg_norm_strength at 0.0 disable the internal patches if you've already wired them externally.
Inputs that matter most
model,clip,vae- wire your Qwen Image Edit model stack.prompt_template- where{tag}gets interpolated per part. Change it per art style.target_pixels(default1024x1024) - working resolution for VAE encode; 1536² is Qwen's max native and ~1.4× slower.alpha_after_edit(defaultauto_from_white_bg) - detects white as transparent in Qwen's output and keeps the full generated shape (no re-cropping to the SAM3 mask, which would re-introduce holes). The other options (fill_holes,original_part, etc.) trade that for different crop behaviors.skip_tags/min_pixels- skip parts by name or tiny crops.
Outputs: parts (the edited bundle), a summary, and image_batch of the rebuilt crops.
Install & the honest caveats
In ComfyUI-BrainDead: Manager search "BrainDead", or clone + pip install -r requirements.txt. This node needs the Qwen Image Edit model (a 20B MMDiT - big, and fp8 + Lightning LoRA are there for a reason). It's a V3-API pack, keep ComfyUI current.
Where people get burned: the internal patches are load-bearing. Disable model_sampling_shift without having ModelSamplingAuraFlow wired externally and the Lightning noise schedule doesn't match the upscaled latent - you get noise stripes instead of a clean render. And if a part's crop is tiny, the node skips it (below min_pixels) and keeps the original, which is correct behavior that reads as "nothing happened" the first time. The true_inpaint mode is the one to reach for when occlusion matters (pants under holster); flatten_redraw is the general-purpose rebuild.
Inputs (32)
| Name | Type | Default | Description |
|---|---|---|---|
| parts | PARTS_BUNDLE | — | |
| model | MODEL | — | |
| clip | CLIP | — | |
| vae | VAE | — | |
| prompt_template | STRING | Recreate the complete {tag} in the same low-poly game style, sharp clean edges, fill any occluded or missing regions, no holes or transparent gaps inside the {tag}, preserve original colors | Per-part prompt. {tag} (or %tag%) is replaced with the part's tag. Default is tuned for low-poly stylized characters with occluded items (e.g. pants under a holster, shirt under a jacket). Adjust for other styles. |
| inpaint_mode | COMBO | flatten_redraw | flatten_redraw (DEFAULT): flatten part RGBA on white bg → Qwen Edit Plus encoder (positive + negative both with image1) → VAE encode → upscale latent by latent_upscale_factor → APPEND upscaled to ref_latents → KSampler → Reinhard tonemap → decode. Generates a clean object render. Default alpha (fill_holes) cuts to original part outline so the composite assembles without white backgrounds. Internal patches: shift=3.0 + cfg_norm=0.85 + tonemap=2.0 — pair with 4-step Lightning LoRA on the input model. true_inpaint: latent-space inpaint with prefill. Source crop pre-filled, noise_mask = enclosed holes. Qwen regenerates only the holes, preserves the rest. Best for completing obstructed parts (pants under holster). Requires source_image wired. |
| latent_upscale_method | COMBO | nearest-exact | Interpolation for latent upscale. nearest-exact preserves encoded values; bilinear/bicubic interpolate values that VAE decodes as noise stripes. |
| prefill_mode | COMBO | white | How to fill HOLE pixels (enclosed cutouts inside the part) in the source crop BEFORE Qwen sees it. white (DEFAULT): solid white. Empirically the best trigger for vanilla Qwen Image Edit 2509 to recognize 'fill this region'. Matches BD_MaskFlatten + invert_mask + white_bg pattern. nearest_part_pixel: Voronoi color spread (preserves shading gradients). average_color: mean color of part pixels. neutral_gray: solid 50% gray. black: REQUIRED for Qwen Image Edit Inpaint LoRA (prompt must start with 'Inpaint the black areas.'). Hard edges only. none: pass source as-is (Qwen sees occluders — usually wrong). |
| target_pixels | COMBO | 1024x1024 | Working resolution for Qwen's VAE encode. Each part's bbox is scaled to approximately this total area (preserving aspect, dims rounded to multiples of 8). 1024² = ~1MP, default for fp8 stability. 1536² = ~2.36MP, Qwen's max native resolution (best quality, ~1.4× slower). Output is resized back to the part's original crop size after inference. |
| seed | INT | 00–18446744073709550000 | Same seed used per part. Set to 0 for randomness; fix for reproducible runs. |
| steps | INT | 41–100 | Sampling steps. 4 for Lightning LoRA. 8-20 for non-Lightning. |
| cfg | FLOAT | 1.00–20 | Classifier-free guidance scale. 1.0 for Lightning (no negative used). |
| sampler_name | COMBO | euler | Lightning LoRA was trained with euler — keep matching. |
| scheduler | COMBO | simple | Lightning LoRA expects simple scheduler. |
| denoise | FLOAT | 1.000–1 | 1.0 = full denoise (typical for edit). Lower = preserve more of the input latent shape. |
| alpha_after_edit | COMBO | auto_from_white_bg | How to compute the part's alpha AFTER the edit: auto_from_white_bg (DEFAULT): detect alpha from white pixels in Qwen's output → white = transparent. The full generated shape is preserved (no SAM3-mask cropping that would re-introduce holes). Cropped to non-white content bbox so the rendered object fits its original part bbox when composited (instead of being lost in white space). Pants obstructed by shirt come out complete with no shirt-shaped chunks missing. fill_holes: part shape with internal enclosed holes flood-filled — cuts generated content to original SAM3 outline + internal fills. original_part: cut exactly to SAM3's mask. Holes stay transparent. original_dilated: original_part + N px dilation (edge feathering). bbox_full: entire crop opaque. Debugging only. |
| source_imageopt | IMAGE | Original source IMAGE (whole frame). Required when inpaint_mode='source_crop'. Lets Qwen see the FULL visual context (e.g. pants WITH the gun on top) so it can properly extract + complete the part underneath. | |
| latent_upscale_factoropt | FLOAT | 1.251–2 | Used by flatten_redraw mode. After encoding the part to latent, upscale by this factor before sampling. Forces the model to denoise/refine (high-res-fix trick). 1.25 is a good default; 1.0 = no upscale. |
| model_sampling_shiftopt | FLOAT | 3.00–20 | Apply ModelSamplingAuraFlow shift internally. REQUIRED for flatten_redraw + latent upscale + Lightning LoRA combo — without it Lightning's noise schedule doesn't match the upscaled latent and you get noise stripes instead of clean output. 3.0 is what the user's manual recipe uses. 0.0 = disabled (use only if you've already wired ModelSamplingAuraFlow externally on the model input). |
| cfg_norm_strengthopt | FLOAT | 0.850–2 | Apply CFGNorm post-cfg function internally. Pairs with the shift patch to keep guidance stable on Lightning + upscale. 0.85 from user recipe. 0.0 = disabled (use only if already wired externally). |
| tonemap_reinhard_multiplieropt | FLOAT | 2.00–10 | Reinhard tonemap on the KSampler output latent (POST-sampling, BEFORE VAE decode). Compresses latent value range to prevent overshoot when running Lightning at upscaled dims. 2.0 from user recipe. 0.0 = disabled. |
| context_extend_factoropt | FLOAT | 1.01–3 | (true_inpaint) CropAndStitch-style context expansion. Multiplier on the part bbox before cropping the source for Qwen. 1.0 = use part bbox as-is. 1.5 = crop 50% bigger so Qwen sees more surrounding visual context. |
| flatten_pad_factoropt | FLOAT | 1.251–2.5 | (flatten_redraw) White-padding around the part image BEFORE encoding. Qwen tends to render content edge-to-edge; padding gives it breathing room so the rendered object isn't cropped at the canvas boundary. 1.25 = 25% extra white on all sides. 1.0 = no padding (Qwen will fill the frame). The canvas dim grows by this factor before encoder fits to target_pixels, so net detail per part is similar. |
| mask_expand_pixelsopt | INT | 00–128 | CropAndStitch-style buffer zone. Dilate the noise_mask outward by N pixels so existing part pixels at the boundary get partially regenerated alongside the holes. Helps the model blend the regen smoothly with the preserved area. 4-8 is a good starting range. 0 = mask exactly matches the detected holes (sharp boundary). |
| mask_blend_pixelsopt | INT | 40–64 | Soft-edge alpha feathering on the FINAL output. Blurs the alpha by N pixels at edges so cutouts blend cleanly with whatever they're composited over. 0 = sharp PNG cutouts. 4-8 = soft anti-aliased edges. |
| target_pixels_customopt | INT | 104857665536–4194304 | Used when target_pixels='custom'. Total pixel budget (e.g. 1048576 = 1024²). |
| negative_promptopt | STRING | Negative prompt (used only when cfg > 1.0). Empty string fine for cfg=1.0. | |
| skip_tagsopt | STRING | Tags to skip entirely (csv or newline). Original images preserved. | |
| min_pixelsopt | INT | 641–10000000 | Skip parts whose RGBA crop is smaller than sqrt(N)x sqrt(N). |
| white_thresholdopt | FLOAT | 0.850.5–1 | Used by alpha_after_edit=auto_from_white_bg. Pixels with luminance > this value AND low saturation are treated as white background → alpha 0. Also auto-samples the 4 corner patches as a bg reference and flags pixels close to that color as transparent (catches off-white tints). Lower = more aggressive. |
| auto_crop_to_contentopt | BOOLEAN | false | When alpha_after_edit=auto_from_white_bg: crop the output RGBA tight to the bbox of opaque (non-white) content. Off by default — when Qwen renders content touching the canvas edges, cropping looks like the object is cut off. Leave OFF to preserve the full rendered output; composite still resizes to fit the part's bbox correctly via the alpha. |
| mask_dilate_pixelsopt | INT | 20–64 | Dilation amount when alpha_after_edit='original_dilated' or 'inpaint_filled' (applied as edge-feather to soften the cut). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| parts | PARTS_BUNDLE | — |
| summary | STRING | — |
| image_batch | IMAGE | — |