Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

java - Getting the most common color of an image

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...