BK Color Luminance
The simpler sibling that just checks how bright a color is
- BG_COLOR
- TEXT_COLOR
If BK Color Contrast is the math-nerd sibling that computes WCAG ratios, BK Color Luminance is the one that eyeballs it. Give it a background color, it computes how bright that color actually is, compares it against a threshold you set, and hands back either a light or dark text color. One number in, one decision out.
It comes from the ComfyUI_BaiKong_Node pack, the no-model, CPU-only color-and-layout toolkit, and it shares DNA with BK Color Contrast - same #RRGGBB parsing, same inline color-swatch preview on the node, same outputs. The difference is the decision rule.
How it works
The node parses your hex to RGB and computes relative luminance using the WCAG formula: each channel is linearized (the <= 0.03928 breakpoint and 2.4 power), then weighted 0.2126/0.7152/0.0722 and summed. If that luminance is greater than your luminance_threshold (default 0.5), the background is "bright," so it returns dark text; otherwise it returns light text.
That's the whole trick, and it's worth understanding the trade-off vs BK Color Contrast. Luminance just thresholds brightness - a mid-saturated mid-gray might get you dark text that technically passes the sniff test but fails a real 4.5:1 AA check. Color Contrast actually tests the candidate text colors against the background and only picks one that clears AA/AAA. So for anything where legibility genuinely matters (subtitles, UI, printed work), reach for Contrast; use Luminance when you just want the cheap "dark text on light, light text on dark" rule wired into a bigger workflow.
Inputs and outputs
- bg_hex_color - your background (default
#FF0036). - luminance_threshold - 0 to 1 slider; 0.5 means "decide on the midpoint."
- light_text_hex_color / dark_text_hex_color - optional, default to
#FFFFFFand#000000when left empty.
Outputs are BG_COLOR and TEXT_COLOR, both hex strings, and it's marked as an output node so the chosen pair renders as a swatch on the node. Wire TEXT_COLOR into whatever draws your labels.
Install
The pack installs as one unit:
cd ComfyUI/custom_nodes
git clone https://github.com/JayLyu/ComfyUI_BaiKong_Node
cd ComfyUI_BaiKong_Node
pip install -r requirements.txt
Restart ComfyUI, or search "ComfyUI_BaiKong_Node" in ComfyUI Manager. Dependencies are scikit-learn, scipy, opencv-python, scikit-image, and matplotlib - all CPU-side, no model downloads, no API keys.
Gotchas
Malformed hex gets a warning and a fallback instead of a crash, and the threshold is clamped to 0–1 internally. The one real surprise is the edge case: because it's a single threshold on a 0–1 scale, most saturated mid-tones land close to 0.5 and can flip-flop with tiny threshold changes. If you find yourself fighting it, that's the sign you actually wanted the contrast-ratio node. And remember - hue plays no part in the decision; a bright yellow and a mid-gray can score the same luminance and get the same answer.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| bg_hex_color | STRING | #FF0036 | — |
| luminance_threshold | FLOAT | 0.500–1 | — |
| light_text_hex_coloropt | STRING | — | |
| dark_text_hex_coloropt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| BG_COLOR | STRING | — |
| TEXT_COLOR | STRING | — |