Hex/RGB to Lab conversion
The input hex or RGB value is converted from sRGB into CIE Lab color space, which separates lightness from the two color-opponent axes (a* for green-red, b* for blue-yellow). Comparing colors in Lab space rather than raw RGB numbers produces a distance measure that tracks human perception more closely than a flat RGB difference would.