Nodes/qwen-whitebg-detector/🎨 White BG Detector (Qwen MultiAngle)
ComfyUI Node

🎨 White BG Detector (Qwen MultiAngle)

It says Qwen, but there's no model in here — and that's the point

By Holonica-Development-Team·Created 3 months ago·Updated 3 months ago· 0
🎨 White BG Detector (Qwen MultiAngle)
  • image
  • bg_prompt
  • detected_type
white_bg_prompt, white background, simple white background
color_bg_prompt
white_ratio_required0.70
pixel_white_threshold0.90
edge_sample_ratio0.08

Let's get the first thing out of the way: the "Qwen" in the name is a lie, and a good one. QwenWhiteBgDetector doesn't load Qwen-Image, doesn't call any API, and doesn't need a key or a model file. It's about thirty lines of torch that look at your image's edges and decide whether the background is white. That's the entire node, and for one very specific workflow - generating multiple angles of the same subject with Qwen-Image-Edit - it quietly fixes a problem you'll otherwise fight for an afternoon.

Here's the situation it exists for. You have a product shot or an object render on a clean white studio background. You feed it to Qwen-Image-Edit and ask for a different camera angle. The model is an LLM-encoded editor with a real attention budget, and if your prompt says nothing about the background, each angle can invent one - grey, beige, a gradient that shifts between frames. Your "multi-angle set" looks like it was shot in different rooms. This node breaks that by reading the actual pixels of your reference image and injecting a background prompt only when the background is actually white.

How it works

No ML is involved anywhere. The node slices the four edges of the image - a band whose width is edge_sample_ratio (default 0.08, so 8% of the shorter dimension) - flattens those strips, and counts pixels where all three RGB channels are at or above pixel_white_threshold (default 0.90). Alpha is ignored, by the way: it only looks at RGB. If the fraction of white edge pixels clears white_ratio_required (default 0.70), you get the white-background prompt. Otherwise you get the fallback. That's it.

The three tuning floats are the only knobs you'll realistically touch:

  • white_ratio_required (0.10–1.0, default 0.70) - how much of the edge has to be white to call it a white background. If your subject bleeds to the frame edges and trips it, nudge this up.
  • pixel_white_threshold (0.50–1.0, default 0.90) - what counts as a "white" pixel. Studio-grey or beige backdrops sit below 0.90; drop this toward 0.85 if your white is off-white.
  • edge_sample_ratio (0.01–0.30, default 0.08) - how deep the sampling band goes. Wider catches more of the background if the subject is large in frame.

The two prompt inputs matter more than they look. white_bg_prompt defaults to , white background, simple white background - note the leading comma, it's designed to be appended to the end of your positive prompt, not inserted in the middle. color_bg_prompt defaults to empty, and the author's own comment says that's usually right: when there's a real background, silence lets Qwen infer naturally instead of you forcing a wrong guess.

Wiring it up

The node has two outputs. bg_prompt (STRING) is the one you care about - concatenate it onto your CLIP text encode / Qwen instruction and you're done. detected_type (STRING) is diagnostic gold: it returns something like white background (edge white ratio: 91%), so you can see the measured ratio and tune the thresholds instead of guessing. Feed it to a display/print node once while you're setting up.

Install

ComfyUI Manager: search "qwen-whitebg-detector" (or just "QwenWhiteBgDetector"). Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/Holonica-Development-Team/QwenWhiteBgDetector.git

Then restart ComfyUI. That's the whole install: pyproject.toml declares zero dependencies beyond the torch ComfyUI already ships, there are no weights to download, and it uses no VRAM worth mentioning. It's the cheapest node you'll add this month.

Where it bites

One real gotcha: it checks only the first frame of the batch (image[0]). Feed it a multi-frame video tensor and frames 2+ are silently ignored. Another: it's an edges-only heuristic, so it assumes your background reaches the borders - a vignette, a drop shadow, or a subject that fills the frame will mislead it. That's exactly why color_bg_prompt is empty by default; when in doubt, let the model figure it out. And remember the leading comma - appending , white background to a template that adds its own punctuation gives you ", , white background" and a pointless double comma in your prompt.

Is it overhyped? For a one-off render, sure, skip it. But if you're generating angle sets where background consistency is the whole deliverable, this beats hand-editing prompts per image - and at zero cost, it's the node you'd reach for.

CategoryQwen MultiAngle

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
white_bg_promptSTRING, white background, simple white background
color_bg_promptSTRING
white_ratio_requiredFLOAT0.700.1–1
pixel_white_thresholdFLOAT0.900.5–1
edge_sample_ratioFLOAT0.080.01–0.3

Outputs (2)

NameTypeDescription
bg_promptSTRING
detected_typeSTRING