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

BD Parts Batch Edit (Qwen)

Iterate every part in a PARTS_BUNDLE inside one execution and run Qwen Image Edit per part. Mutates tag2pinfo[tag]['img'] with the edited result. Designed for the Qwen Image Edit 2509 fp8 stack with the 4-step Lightning LoRA — defaults match that setup (steps=4, cfg=1.0, sampler=euler, scheduler=simple). Each part's prompt is built by interpolating {tag} into prompt_template, e.g. 'rebuild this {tag} in the same style'. The part's RGBA is composited onto neutral gray for inference, then the original alpha is reapplied so edges stay clean. Skips parts whose tag matches skip_tags (csv/newline). For tags with tiny crops (below min_pixels) the edit is skipped and original kept.

By BizaNator·Created 7 months ago·Updated 16 days ago· 14
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
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