从图像中提取主要/最常用的颜色
我想提取图像中最常用的颜色,或者至少提取主色调 您能建议我如何开始这项任务吗?或者给我指出类似的代码?我一直在寻找但没有成功。
I would like to extract the most used colors inside an image, or at least the primary tones
Could you recommend me how can I start with this task? or point me to a similar code? I have being looking for it but no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用八叉树颜色量化算法可以获得非常好的结果。其他量化算法可以在维基百科上找到。
You can get very good results using an Octree Color Quantization algorithm. Other quantization algorithms can be found on Wikipedia.
我同意这些评论 - 编程解决方案肯定需要更多信息。但在那之前,假设您将获得图像中每个像素的 RGB 值,您应该考虑 HSV色彩空间,其中色调可以说代表每个像素的“色调”。然后,您可以使用直方图来识别图像中最常用的色调。
I agree with the comments - a programming solution would definitely need more information. But till then, assuming you'll obtain the RGB values of each pixel in your image, you should consider the HSV colorspace where the Hue can be said to represent the "tone" of each pixel. You can then use a histogram to identify the most used tones in your image.
好吧,我假设您可以访问每个像素的 RGB 颜色。有两种方法可以选择,具体取决于您想要的方式。
首先,您可以简单地创建所有像素的一些 R、G 和 B。就像这样。
伪代码。
然后看哪个多一些。
这给你的只是图片更红、更绿或者更蓝。
另一种方法也可以通过简单地创建每个 RGB 组合的直方图来为您提供组合颜色的静态(如橙色)。
伪代码。
然后看哪一个的数多一些。
您还可以降低颜色分辨率,因为常规 RGB 着色最多可为您提供 670 万种颜色。
通过将 RGB 指定为颜色范围,可以轻松完成此操作。例如,RGB 是 8 步,而不是 256。
伪代码。
然后您可以看到哪个范围的计数最多。
我希望这些技术对您有意义。
Well, I assume you can access to each pixel RGB color. There are two ways you can so depending on how you want it.
First you may simply create some of all pixel's R, G and B. Like this.
A pseudo code.
Then see which is more.
This give you only the picture is more red, green or blue.
Another way will give you static of combined color too (like orange) by simply create histogram of each RGB combination.
A pseudo code.
Then see which one has more count.
You may also reduce the color-resolution as a regular RGB coloring will give you up to 6.7 million colors.
This can be done easily by given the RGB to ranges of color. For example, let say, RGB is 8 step not 256.
A pseudo code.
Then you can see which range have the most count.
I hope these technique makes sense to you.