Nodes/BrainDead Nodes/BD Parts Batch Edit (Qwen)
ComfyUI Node

BD Parts Batch Edit (Qwen)

Redraw every part of a character in one run — BD Parts Batch Edit (Qwen)

By BizaNator·Created 8 months ago·Updated 3 days ago· 15
BD Parts Batch Edit (Qwen)
  • parts
  • model
  • clip
  • vae
  • source_image
  • parts
  • summary
  • image_batch
prompt_templateRecreate 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
inpaint_modeflatten_redraw
latent_upscale_methodnearest-exact
prefill_modewhite
target_pixels1024x1024
seed0
steps4
cfg1.0
sampler_nameeuler
schedulersimple
denoise1.00
alpha_after_editauto_from_white_bg
latent_upscale_factor1.25
model_sampling_shift3.0
cfg_norm_strength0.85
tonemap_reinhard_multiplier2.0
context_extend_factor1.0
flatten_pad_factor1.25
mask_expand_pixels0
mask_blend_pixels4
target_pixels_custom1048576
negative_prompt
skip_tags
min_pixels64
white_threshold0.85
auto_crop_to_contentfalse
mask_dilate_pixels2

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 by latent_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. Requires source_image wired 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 (default 1024x1024) - working resolution for VAE encode; 1536² is Qwen's max native and ~1.4× slower.
  • alpha_after_edit (default auto_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.

Category🧠BrainDead/Segmentation

Inputs (32)

NameTypeDefaultDescription
partsPARTS_BUNDLE
modelMODEL
clipCLIP
vaeVAE
prompt_templateSTRINGRecreate 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 colorsPer-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_modeCOMBOflatten_redrawflatten_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_methodCOMBOnearest-exactInterpolation for latent upscale. nearest-exact preserves encoded values; bilinear/bicubic interpolate values that VAE decodes as noise stripes.
prefill_modeCOMBOwhiteHow 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_pixelsCOMBO1024x1024Working 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.
seedINT00–18446744073709550000Same seed used per part. Set to 0 for randomness; fix for reproducible runs.
stepsINT41–100Sampling steps. 4 for Lightning LoRA. 8-20 for non-Lightning.
cfgFLOAT1.00–20Classifier-free guidance scale. 1.0 for Lightning (no negative used).
sampler_nameCOMBOeulerLightning LoRA was trained with euler — keep matching.
schedulerCOMBOsimpleLightning LoRA expects simple scheduler.
denoiseFLOAT1.000–11.0 = full denoise (typical for edit). Lower = preserve more of the input latent shape.
alpha_after_editCOMBOauto_from_white_bgHow 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_imageoptIMAGEOriginal 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_factoroptFLOAT1.251–2Used 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_shiftoptFLOAT3.00–20Apply 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_strengthoptFLOAT0.850–2Apply 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_multiplieroptFLOAT2.00–10Reinhard 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_factoroptFLOAT1.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_factoroptFLOAT1.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_pixelsoptINT00–128CropAndStitch-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_pixelsoptINT40–64Soft-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_customoptINT104857665536–4194304Used when target_pixels='custom'. Total pixel budget (e.g. 1048576 = 1024²).
negative_promptoptSTRINGNegative prompt (used only when cfg > 1.0). Empty string fine for cfg=1.0.
skip_tagsoptSTRINGTags to skip entirely (csv or newline). Original images preserved.
min_pixelsoptINT641–10000000Skip parts whose RGBA crop is smaller than sqrt(N)x sqrt(N).
white_thresholdoptFLOAT0.850.5–1Used 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_contentoptBOOLEANfalseWhen 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_pixelsoptINT20–64Dilation amount when alpha_after_edit='original_dilated' or 'inpaint_filled' (applied as edge-feather to soften the cut).

Outputs (3)

NameTypeDescription
partsPARTS_BUNDLE
summarySTRING
image_batchIMAGE