← sources

How I get transparent backgrounds with my own LoRA: render on white, re-render on black

source: reddit (reddit:StableDiffusion)published 2026-10-14 10:42ingested 2026-10-15 02:40

retained text

I am making a 2D game with FLUX.2 klein 4B and a style LoRA and needed transparent backgrounds. LayerDiffuse is SD1.5/SDXL only, hosted models with alpha don't take my LoRA, and background removers either ate the white eyes or left a white halo on dark scenes.

What works for me is old film matting (Smith & Blinn 1996, triangulation):

1. Generate the character on white.

2. Pass that image back as the reference with "the same subject, unchanged, on a solid black background". Same seed alone is not enough, a rerun moved 11-29% of pixels. The reference keeps the figure in place.

3. alpha = 1 - (white - black) / 255, colour taken from the black image so there is no white fringe.

Whatever looks the same in both is opaque, whatever flips is background.

It still broke on enclosed gaps, like the space between the legs. The model doesn't repaint them black, so they stay white and therefore opaque. Prompting for black didn't help. So I added a segmentation model to clear those, only for areas above 0.1% of the image that it mostly calls background, so it stops cutting eye whites. Small real gaps get missed.

Has anyone cleared enclosed gaps without segmentation?

Which edit models besides klein 4B keep the figure pixel-stable on a background swap?

What other methods for reliable AI image generation on transparent background exist?

document fetched 2026-10-15 00:34 · canonical https://reddit.com/r/StableDiffusion/comments/1x5nx9m/how_i_get_transparent_backgrounds_with_my_own