It is difficult to accurately judge how much a piece of text or an object will stand out against a background just by looking at the colors.
It calculates a score by measuring the difference between two colors while accounting for how bright they actually appear to the human eye.
It provides a more accurate way to measure how much an element will pop against its background.
It was run inside an isolated container with no network access. This is the exact command and the real output it produced — captured process output, not written by a model.
$ python3 visibility_score.py Contrast-Weighted Visibility Score: 21.0320
A screenshot of that run.
A clean run proves this does what is shown above, in a CPU-only sandbox. It is a small research demo — not a production tool, and nothing here was published anywhere.
All of it — 42 lines, one file, standard library only.
# Contrast-Weighted Visibility Score Calculator
import math
def euclidean_distance(fg, bg):
"""
Calculate Euclidean distance between two RGB colors
"""
return math.sqrt(sum((a - b)**2 for a, b in zip(fg, bg)))
def luminance(rgb):
"""
Calculate relative luminance (0-1) from RGB values (0-255)
"""
r, g, b = [x / 255.0 for x in rgb]
return 0.2126 * r + 0.7152 * g + 0.0722 * b
import sys
def contrast_ratio(fg, bg):
"""
Calculate WCAG luminance contrast ratio
"""
L_fg = luminance(fg)
L_bg = luminance(bg)
L1 = max(L_fg, L_bg)
L2 = min(L_fg, L_bg)
return (L1 + 0.05) / (L2 + 0.05)
def visibility_score(fg, bg):
"""
Calculate contrast-weighted visibility score
"""
distance = euclidean_distance(fg, bg)
cr = contrast_ratio(fg, bg)
return distance / cr
if __name__ == "__main__":
# Example usage with white on black
fg = (255, 255, 255) # White
bg = (0, 0, 0) # Black
score = visibility_score(fg, bg)
print(f"Contrast-Weighted Visibility Score: {score:.4f}")