## How to count colors in an image or series of images?

### Question

Perhaps this question is too technical for this subsite, if so, please relocate it to a better spot.

I'm doing some research on colors where I need to figure out how common colors are. The end result will be a bunch of charts, somewhat similar to this flag analysis.

I will have 50+ sets of 100 or so images and I want to calculate the color distribution in each set, and then compare the averages of each set. Which is the most common color in all sets, are there changes/trends between sets, and so on. With thousands of images obviously it's not feasible to count all pixels myself and decide what colors are most prominent. So I'd like to automate.

Ideally, I'd have a tool that looks at each set and quantizes colors based on a palette I create myself. I'd also love it if the tool would accept a series of different-sized images, but I'm willing to rescale and combine each series in to a single collage.

Note: I'm looking for something that lists PIXEL colors, not IMAGE AVERAGE colors. Since I will have images that have multiple colors, looking at the average or most prominent color gives misleading results. For example, in the following image there are several images that use a rainbow of colors, but do not get placed near eachother.

And this image is predominantly blue, but should still count for about 1/3rd as green pixels:

Or even worse, the following image uses bright green and red, but would either be categorized as yellow (average hue) or grayish (average of RGB values):

To recap: I'm looking for a tool that can reduce an image to a small (specified) color palette, and then count how many pixels of each of those colors there are.

2016/06/22
1
3
6/22/2016 3:21:00 PM

Interesting question.

On Photoshop:

1) Multiply your image dimensions. For example 640x480= 307,200 Save this number (total value), probably on an excell table.

2) Convert your image to 8 bit

• Mode > 8 bit

• Choose an amount of colors. Lets say the double of the palete you can refine the palete later. Keep it in manageable values. for example 16-24 colors to refine it later to 8.

• Palete Local, dither none.

3) Adjust the palete as needed

• Image > Mode > Color Table

4) Select Color range and choose one or several similar colors using the tolerance slider.

5) Open the histogram and turn on the extended view. Window > Histogram.

• This is now counting the pixels inside the selection.

6) Divide the total value / selected value and you now have the percentage of thoose colors.

7) Repeat as necesary depending on the palete you choosed.

2016/09/20
1
9/20/2016 7:33:00 PM