获取图像的最常见的颜色 [英] Getting the most common color of an image

查看:199
本文介绍了获取图像的最常见的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图片中获得最常见的颜色。我使用Java和我想要最主要的颜色。有没有任何cbir java库来做这个?

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?

谢谢

推荐答案

>你希望这是多么准确?你可以使用Bozhos的方法和循环整个图像,但对于大图像,这可能很慢。在地图中有16777216个可能的RGB值和保持计数器不是非常有效。

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.

另一种方法是使用 getScaledInstance 将其缩小到较小的版本例如1x1图像,然后使用 getRGB 获取该像素的颜色。您可以尝试不同的重复抽样算法,例如 SCALE_REPLICATE SCALE_AREA_AVERAGING 查看什么最适合您。

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.

这篇关于获取图像的最常见的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆