Take the 2-minute tour ×

I'm looking for an idea for getting the most representative color in a grid of pixels. There is any algorithm for this? I'm not sure if the most representative is one of the colors appearing in the grid of is the average af all the pixels better?

alt text

share|improve this question
"Average" of the pixels? What will that be? Color #888888 is Grey. –  S.Lott Feb 20 '10 at 13:56
Representative in what sense? What will the representatives be used for? –  f3lix Feb 20 '10 at 13:58
Taking the average would indeed tend to grey if you are working in the RGB space. An alternative could be to take the average in the HSL (or HSV) space. –  Patrick Feb 20 '10 at 14:22
I'm trying to create a "color palette" from a picture :D –  kiewic Feb 21 '10 at 18:12

2 Answers 2

up vote 1 down vote accepted

Have a look at some color quantization algorithms. I found them to be the most effective method to generate palettes from photographs. Also, most image manipulation/processing libraries should have some fast quantization built in.

share|improve this answer

You are probably looking at "average" as percepted by human. First you need to change you colors representation in a color space that is specially designed to be "perceptually uniform" (for calculation of color "distances") L*a*b* link text Then, each color is a point in 3D color space. Now you can find the "center" of the cloud of points and this is the "most representative color".

share|improve this answer
@Ross this sounds good, I'll try it. –  kiewic Mar 1 '10 at 22:36

Your Answer


