PDA

View Full Version : How detect dominant color in a picture?



antartide
10th May 2011, 16:48
I have to detect dominant color in a picture, have any idea about?
This is why I want to draw a shadow with the dominant color of my app background.

SixDegrees
10th May 2011, 17:26
This is a tricky problem without some constraints placed on it. If you're working with screen images of a GUI, it may be as simple as counting pixels of a handful of screen colors to see which is most prevalent. If you're working with continuous-tone photographs, you'll have to do something like bin each pixel into a histogram based on Hue in HSV space, then (maybe) take the average of HSV in the bin with the most pixels.

Even then, you may have to account for "blobs", areas in the picture where a particular color is dominant, while other colors which may be more numerically prevalent will be ignored because they are disconnected or diffused throughout the image.

A simple, not very accurate approach might be to reduce the image to the size of a single pixel using one of the more rigorous interpolation techniques, then measure the value of that single pixel. Faster and less work than doing it right, and it might even work.

Another approach would be a modified Median Cut algorithm, looking for the largest partitioned volume in whatever color space is used. Again, HSV would probably be best here.