根据某些条件在直方图中找到两个最大峰值

时间:2015-06-03 12:04:05

标签: matlab max histogram

在前两张图片中,在使用matlab函数找到的所有峰值中,找到了峰值,我已经标记了红色'我想要找到的峰值,条件是在它们之间找到两个具有最小值的最大峰值的位置。

enter image description here

对于下面的直方图,不满足条件,因此,没有两个峰值。

enter image description here 有任何想法吗, 谢谢

两个第一张图像的直方图值:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5,60000000000000 11,4000000000000 17,2000000000000 23,6000000000000 30,4000000000000 33,6000000000000 38 44,2000000000000 47,0000000000000 45,6000000000000 37,4000000000000 27,4000000000000 15,4000000000000 6,20000000000000 2,20000000000000 3,60000000000000 5,40000000000000 7 7,60000000000000 6,20000000000000 4,20000000000000 2,20000000000000 1 1,20000000000000 2,20000000000000 3,60000000000000 5,80000000000000 7,80000000000000 9 9,20000000000000 8,60000000000000 7,20000000000000 5,60000000000000 5,60000000000000 8 12 16,8000000000000 22,2000000000000 25,8000000000000 27,2000000000000 26,8000000000000 25,2000000000000 22,8000000000000 22 22,4000000000000 23,6000000000000 28,2000000000000 34,6000000000000 38,4000000000000 40 37,6000000000000 29 18,8000000000000 10,2000000000000 3,20000000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0,600000000000000 1,40000000000000 2,20000000000000 3 3,80000000000000 4 4 4,20000000000000 4,20000000000000 4,20000000000000 4,20000000000000 4,20000000000000 4 4 4 4 4,20000000000000 4,40000000000000 4,60000000000000 4,80000000000000 5,20000000000000 5,40000000000000 5,60000000000000 5,80000000000000 5,80000000000000 5,80000000000000 5,60000000000000 5,40000000000000 五 4,60000000000000 3,40000000000000 2,40000000000000 1,40000000000000 0,600000000000000 0 0 0 0 0 0 0 0 0 0 0 0 0,200000000000000 0,400000000000000 0,600000000000000 1 1,40000000000000 1,60000000000000 1,80000000000000 3,20000000000000 4,60000000000000 5,80000000000000 6,80000000000000 7,40000000000000 6,80000000000000 6,20000000000000 5,80000000000000 5,40000000000000 5,20000000000000 5,20000000000000 五 4,80000000000000 五 6,20000000000000 7,40000000000000 7,20000000000000 6,80000000000000 5,60000000000000 3,60000000000000 1,40000000000000 0,600000000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3 个答案:

答案 0 :(得分:1)

您可以预处理我们的数据,以排除低于阈值的所有值:

data(data<threshold) = 0

然后你可以使用

[maxval, index] = max(data)

获取最大值和索引。接下来,您可以查找低于或等于maxval的峰值,例如:

data(index) = 0; [maxval, index] = max(data)

将为您提供下一个峰值(也是相等的值)和它的索引。

通过重复此过程,您可以找到所有峰的索引和值,从最大到最小。

答案 1 :(得分:1)

Polystep方法

第1步,定义您的阈值并找到低于/高于

的所有值
minval = 20;
f = zeros(size(h));
f(h<minval) = 1;

第2步,使用此代码your previous question并删除空单元格

id = cumsum(f)+1;   
mask = f==0;        
groups = accumarray(id(mask).',h(mask).',[],@(x) {x});
groups(isempty(groups)) = [];
groups=groups(~cellfun('isempty',groups));  

找到所有最大值

maxvals = cellfun(@(x) max(x), groups)

答案 2 :(得分:0)

非常感谢你的回答, 这非常有效

    S % the Histogram
    TH % threshold
    [pks,locs] = findpeaks(S,'SortStr','descend'); % find peaks
            if size(locs,1)>=2
                for j=1:size(locs,1)-1
                    if locs(j+1)<locs(1)
                        Interval=S(locs(j+1):locs(1));
                    else
                        Interval=S(locs(1):locs(j+1));
                    end 
                    minimum=min(Interval);
                    if minimum<=TH;
                        plot(locs(j+1),pks(j+1),'go','lineWidth',4); 
                        plot(locs(1),pks(1),'go','lineWidth',4); 
                        break;
                    end
                end
            end