好了,我有一个直方图(通过int数组表示),和我正在寻找寻找局部最大值和最小值的最佳途径。 每个直方图应该有3个峰值,其中一个(第一个)可能比其他人高得多。
我想要做的几件事情:
找到第一个“谷”之后的第一个高峰(为了获得在画面完全摆脱了第一个高峰)
查找之间的剩余的两个峰的图像分离的最佳“谷”值
我已经知道如何通过实施大津的变体,做第2步。 但我与步骤1中挣扎
如果在剩下的两个波峰之间的波谷不够低,我想给一个警告。
此外,图像是很少噪声占相当干净
什么是蛮力算法来执行步骤1和3? 我能找到一种方法来实现大津,但蛮力是逃避我,数学明智的。 事实证明,对做这样的Otsu方法的详细资料,而减少对简单的寻找波峰和波谷。 我找不到任何比任何能够完成任务更(即它是一个临时的解决办法,只是要在合理的时间内实现的,直到我可以花更多的时间就可以了)
我做这一切在C#
在其任何帮助步骤能够将不胜感激! 非常感谢!
编辑:一些数据:
最直方图很可能是像第一个,与代表背景的第一个高峰。
![](https://www.manongdao.com/static/images/pcload.jpg)
![](https://www.manongdao.com/static/images/pcload.jpg)
使用peakiness测试。 这是找到两个局部最小值之间的所有可能的峰值,并测量基于公式的peakiness的方法。 如果高于阈值的peakiness,峰值被接受。
来源: 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;
}