1

I'm trying to build an app for a class project that finds the most dominant color of an image. While it's not hard to extract the most dominant colors RBG code, I was wondering if there is a way to use this code to get us the name of the color like red color or blue color. I understand this would be technically complex since there are so many different RGB values but I was wondering if that had been done before. I'm using Swift to develop this app.

Uditi
  • 19
  • 2

1 Answers1

0

This question is not swift related but more a general programming problem. There are multiple ways to solve this.

The first approach would be to create a list of colors you want to separate, or get it from somewhere. Then create a function that maps a random RGB value onto the nearest values from the list (you can do least squares or any kind of definition of 'nearest values').

Another solution would be to again use a mapping but based on the angle of the rgb values when mapped into an rgb color wheel (https://www.pikpng.com/pngl/b/113-1130205_alt-text-rgb-led-color-mixing-chart-clipart.png, http://www.procato.com/rgb+index/).

Anyway, there are multiple solutions online and also on stack overflow (RGB color space to raw color name mapping, https://github.com/ayushoriginal/Optimized-RGB-To-ColorName)

Simon
  • 2,419
  • 2
  • 18
  • 30