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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With