"You're basically just running kmeans on the pixels, right? If that's correct, I'd strongly recommend you use a "perceptually uniform" color space and distance metric, like CIELAB. Even HSV would be better than RGB. The issue with just using RGB is that perceived color proximity doesn't correlate well to euclidean distance in RGB space. Two colors can be "numerically close" in RGB without being perceptually similar."
https://www.reddit.com/r/Python/comments/dmzs6s/i_created_a_python_script_to_generate_color/f570vcv/?context=3
"You're basically just running kmeans on the pixels, right? If that's correct, I'd strongly recommend you use a "perceptually uniform" color space and distance metric, like CIELAB. Even HSV would be better than RGB. The issue with just using RGB is that perceived color proximity doesn't correlate well to euclidean distance in RGB space. Two colors can be "numerically close" in RGB without being perceptually similar." https://www.reddit.com/r/Python/comments/dmzs6s/i_created_a_python_script_to_generate_color/f570vcv/?context=3