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
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.
getScaledInstance
getRGB
1.4m articles
1.4m replys
5 comments
56.9k users