【问题标题】:Count unique colors of RGB Image using OpenCV/EmguCV使用 OpenCV/EmguCV 计算 RGB 图像的唯一颜色
【发布时间】:2015-12-15 06:12:06
【问题描述】:

如何计算图像 ROI 的独特颜色。 我尝试使用直方图,但我不知道如何处理 Bin 值。到目前为止,这是我使用 EMguCV 的代码:

image.ROI= new Rectangle(10,10,300,500);
Image<Gray, Byte>[] gray = image.Split(); 
DenseHistogram hist = new DenseHistogram(256, new RangeF(0f, 256f));
hist.Calculate(new Image<Gray, byte>[] { gray[0] }, false, null);
float[] r = hist.GetBinValues();
hist.Calculate(new Image<Gray, byte>[] { gray[1] }, false, null);
float[] g = hist.GetBinValues();
hist.Calculate(new Image<Gray, byte>[] { gray[2] }, false, null);
float[] b = hist.GetBinValues();

如何计算 r,g,b 值来获得使用颜色的数量?

【问题讨论】:

    标签: opencv colors histogram emgucv


    【解决方案1】:

    我不知道你是否会为此感到高兴。但是蛮力方法是

     Image<Bgr, byte> test = new Image<Bgr, byte>(@"C:\Lena.jpeg");
            List<Bgr> thePixelList = new List<Bgr>();
            for (int j = 0; j < test.Cols; j++)
            {
                for (int i = 0; i < test.Rows; i++)
                {                  
                    thePixelList.Add(test[i, j]);
    
                }
            }
    
    
            int theCount = thePixelList.Distinct().Count();
    

    【讨论】:

    • 感谢您的建议,我也考虑过,但这种方法需要太多时间。
    • 当我读到你的问题时,这是一个“选择不同”的问题。此外,我记得“选择不同”是一个 NP 难题。因此,您将需要两个步骤。 - 将数据复制到另一个数组(除非你想就地排序) - 使用 NP-Hard Distinct。我不知道你将如何解决这个问题。
    • 是的,上面的循环看起来非常 NP-Hard。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    相关资源
    最近更新 更多