Menu

Why sRGB Euclidean Distance Fails on Paint Swatches (And How CIEDE2000 Fixes It)
📰

Why sRGB Euclidean Distance Fails on Paint Swatches (And How CIEDE2000 Fixes It)

DEV Community: javascript·Someesim·6 days ago
#vS5kD9vP
#devtojavascript#devto#dev#paint#standard
Reading 0:00
15s threshold

If you sample a wall color from a room photograph—say #DCE3E6 —and search a database of 15,000 commercial paint swatches using standard RGB Euclidean distance, the top result frequently looks visibly purple or green once rolled onto drywall.

1. Non-Linearity of sRGB Gamma Encoding

Standard hex codes live in gamma-compressed sRGB space rather than linear light intensity. Before comparing two colors, each channel C_srgb in [0, 1] must be linearized:

const linearize = ( c ) => ( c <= 0.04045 ? c / 12.92 : Math . pow ( ( c + 0.055 ) / 1.055 , 2.4 ) ) ;

Enter fullscreen mode

Exit fullscreen mode

Once linearized, the relative luminance Y = 0.2126 * R + 0.7152 * G + 0.0722 * B maps directly to the paint industry's Light Reflectance Value (LRV, 0–100) printed on the back of fan decks from Sherwin-Williams, Benjamin Moore, and Behr.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.