It'd be better to convert to HSL, and compute the distance from there.
HSL-distance preserves color similarity with higher fidelity than converting both pixels to greyscale as done in the shared link
HSL-distance preserves color similarity with higher fidelity than converting both pixels to greyscale as done in the shared link
But my comment was addressing parent's point that pure blue and pure red are currently considered close together since they share the same greyscale values.