查找直方图的局部最大值/峰值和最小值/谷值

Edw*_*inG 9 image-processing mathematical-optimization histogram image-segmentation c#-4.0

好吧,所以我有一个直方图(由一组整数表示),我正在寻找找到局部最大值和最小值的最佳方法.每个直方图应该有3个峰值,其中一个(第一个)可能比其他峰值高得多.

我想做几件事:

  1. 在第一个峰值之后找到第一个"山谷"(为了完全消除图中的第一个峰值)

  2. 找到剩余两个峰之间的最佳"谷值"以分离图片

    我已经知道如何通过实现Otsu的变体来执行第2步.但我正在努力迈出第1步

  3. 如果两个剩余峰值之间的山谷不够低,我想发出警告.

此外,图像非常干净,几乎没有噪音

执行步骤1和3的蛮力算法是什么?我可以找到一种方法来实现Otsu,但是数学方面的蛮力正在逃避我.事实证明,有更多关于像otsu这样的方法的文档,而不是简单地找到峰值和谷值.我不是在寻找任何比完成工作更多的东西(即它是一个临时解决方案,只需要在合理的时间范围内实施,直到我可以花更多的时间在它上面)

我在c#中做这一切

任何有关采取哪些步骤的帮助将不胜感激!非常感谢!

编辑:更多数据:

大多数直方图可能与第一个直方图相似,第一个峰值代表背景.

直方图

直方图2

bol*_*oli 4

使用峰值测试。它是一种寻找两个局部极小值之间所有可能的峰值,并根据公式测量峰值的方法。如果峰值高于阈值,则接受该峰值。

资料来源:UCF CV CAP5415 讲座 9 幻灯片

下面是我的代码:

public static List<int> PeakinessTest(int[] histogram, double peakinessThres)
{
    int j=0;
    List<int> valleys = new List<int> ();

    //The start of the valley
    int vA = histogram[j];
    int P = vA;

    //The end of the valley
    int vB = 0;

    //The width of the valley, default width is 1
    int W = 1;

    //The sum of the pixels between vA and vB
    int N = 0;

    //The measure of the peaks peakiness
    double peakiness=0.0;

    int peak=0;
    bool l = false;

    try
    {
        while (j < 254)
        {

            l = false;
            vA = histogram[j];
            P = vA;
            W = 1;
            N = vA;

            int i = j + 1;

            //To find the peak
            while (P < histogram[i])
            {
                P = histogram[i];
                W++;
                N += histogram[i];
                i++;
            }


            //To find the border of the valley other side
            peak = i - 1;
            vB = histogram[i];
            N += histogram[i];
            i++;
            W++;

            l = true;
            while (vB >= histogram[i])
            {
                vB = histogram[i];
                W++;
                N += histogram[i];
                i++;
            }

                //Calculate peakiness
            peakiness = (1 - (double)((vA + vB) / (2.0 * P))) * (1 - ((double)N / (double)(W * P)));

            if (peakiness > peakinessThres & !valleys.Contains(j))
            {
                //peaks.Add(peak);                        
                valleys.Add(j);
                valleys.Add(i - 1);
            }

            j = i - 1;
        }
    }
    catch (Exception)
    {
        if (l)
        {
            vB = histogram[255];

            peakiness = (1 - (double)((vA + vB) / (2.0 * P))) * (1 - ((double)N / (double)(W * P)));

            if (peakiness > peakinessThres)
                valleys.Add(255);

                //peaks.Add(255);
            return valleys;
        }   
    }

        //if(!valleys.Contains(255))
        //    valleys.Add(255);

    return valleys;
}
Run Code Online (Sandbox Code Playgroud)