Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the most common color of an image

Tags:

java

colors

cbir

I'd like to get the most common color from an image. I use Java and I want to have the most predominant color. Are there any cbir java library to make this?

Thanks

like image 671
Sergio Avatar asked Dec 13 '10 09:12

Sergio


People also ask

How do you identify primary colors?

Primary, secondary and tertiary colorsPrimary colors in the RGB color wheel are the colors that, added together, create pure white light. These colors are red, green and blue. In the RYB color wheel, primary colors are colors that can't be mixed from other colors. There are three primary colors: red, yellow, and blue.

What is the most dominant color?

Look at the strength of the red dress above; it is easily the most dominant color on the website. These colors are most dominant when used without tints, tones or shading.


1 Answers

How accurate do you want this to be? You can use Bozhos's approach and loop over the entire image but this could be slow for large images. There are 16777216 possible RGB values and keeping counters for them in a Map is not very efficient.

An alternative is to resample the image using getScaledInstance to scale it down to a smaller version e.g. a 1x1 image and then use getRGB to get the colour of that pixel. You can experiment with different resampling algorithms such as SCALE_REPLICATE and SCALE_AREA_AVERAGING to see what works best for you.

like image 191
dogbane Avatar answered Sep 24 '22 17:09

dogbane