获得优势颜色opencv [英] Getting dominance color opencv
问题描述
我有一张多色的图片。
我想计算图像的主色。主色为红色,我想过滤掉红色。我在opencv中执行以下代码,但它不执行。
inRange(input_image,Scalar(0,0,0),Scalar(0,0,255),output);
否则我如何获得主色?我的最终项目应该自己确定对象的最大颜色。这是最好的方法是什么?
(0,0,255)
(蓝色int RGB)的100个像素的图像,(0,0,254)的100个像素
(几乎是蓝色 - 你甚至不会找到差别)和150像素的(0,255,0)
(绿色)。这里最常见的颜色是什么?显然,它是绿色的。 阅读这个讨论:如何使用OpenCV减少图像中的颜色数量?下面是一个简单的例子:
int coef = 200;
Mat quantized = img / coef;
quantized = quantized * coef;
这是我应用它之后得到的:
>
也可以使用k-means或mean-shift来做到这一点(这是非常有效的方法)。
I have a image which is multi colored.
I want to calculate the dominant color of the image. the dominant color is red, i want to filter the red out. i am doing the following code in opencv but its not performing.
inRange(input_image, Scalar(0, 0, 0), Scalar(0, 0, 255), output);
How can i get the dominant color otherwise? My final project should determine the maximum color of the object on its own. What is the best method for this?
You should quantize (reduce number of colors) your image before searching the for the most frequent color.
Why? Imagine image that has 100 pixels of (0,0,255)
(blue color int RGB), 100 pixels of (0,0,254)
(almost blue - you even won't find the difference) and 150 pixels of (0,255,0)
(green). What is the most frequent color here? Obviously, it's green. But after quantization you will got 200 pixels of blue and 150 pixels of green.
Read this discussion: How to reduce the number of colors in an image with OpenCV?. Here's simple example:
int coef = 200;
Mat quantized = img/coef;
quantized = quantized*coef;
And this is what I've got after applying it:
Also you can use k-means or mean-shift to do that (this is much efficient way).
这篇关于获得优势颜色opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!