• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

[转载]matlab 局部极值点搜索

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
原文地址:matlab 局部极值点搜索作者:秋楚驿
Description This is a very simple function to find the local maximum in any dimensional array. As simple as it is it still gives nice results.
I use the imdilate() function as a maximum operation and then compare the data to the result.
The function receives three parameters: 
the data, a vector defining the minimum distance between peaks in each of the data dimensions. and a flag either to exclude equal points or not.
use examples: 
a = cumsum(randn(1000,1)); 
peaks = localMaximum(a,[100]); 
figure; plot(a); hold on; plot(peaks,a(peaks),'ro');
[x y] = meshgrid(-6:0.1:6,-6:0.1:6); 
a = sinc(x).*sinc(y); 
lMaxInd = localmaximum(a,[20 20]); 
lMinInd = localMaximum(-a,[20 20]); 
figure; mesh(x,y,a); hold on; 
plot3(x(lMaxInd),y(lMaxInd),a(lMaxInd),'k*','markersize',10,'linewidth',1.5); 
plot3(x(lMinInd),y(lMinInd),a(lMinInd),'g*','markersize',10','linewidth',1.5); 
legend('sinc(x)sinc(y)','peaks','valleys','location','best')
P.S 
- It is recommended to run (if possible) a LPF on the data before searching for the peaks
Required Products  Image Processing Toolbox
MATLAB release MATLAB 7.0.4 (R14SP2) 



function varargout = localMaximum(x,minDist, exculdeEqualPoints)
% function varargout = localMaximum(x,minDist, exculdeEqualPoints)
%
% This function returns the indexessubscripts of local maximum in the data x.
% x can be a vector or a matrix of any dimension
%
% minDist is the minimum distance between two peaks (local maxima)
% minDist should be a vector in which each argument corresponds to it's
% relevant dimension OR a number which is the minimum distance for all
% dimensions
%
% exculdeEqualPoints - is a boolean definning either to recognize points with the same value as peaks or not
% x = [1     2     3     4     4     4     4     4     4     3     3     3     2     1];  
%  will the program return all the '4' as peaks or not -  defined by the 'exculdeEqualPoints'
% localMaximum(x,3)
% ans = 
%      4     5     6     7     8     9    11    12
%
%  localMaximum(x,3,true)
% ans =
%      4     7    12
%      
%
% Example:
% a = randn(100,30,10);
% minDist = [10 3 5];
% peaks = localMaximum(a,minDist);
% To recieve the subscript instead of the index use:
% [xIn yIn zIn] = localMaximum(a,minDist);
%
% To find local minimum call the function with minus the variable:
% valleys = localMaximum(-a,minDist);

    if nargin < 3
        exculdeEqualPoints = false;
        if nargin < 2
            minDist = size(x)/10;
        end       
    end
    
    if isempty(minDist)
        minDist = size(x)/10;
    end
    
    dimX = length ( size(x) );
    if length(minDist) ~= dimX
        % In case minimum distance isn't defined for all of x dimensions
        % I use the first value as the default for all of the dimensions
        minDist = minDist( ones(dimX,1) );
    end
    
    % validity checks
    minDist = ceil(minDist);
    minDist = max( [minDist(:)' ; ones(1,length(minDist))] );
    minDist = min( [minDist ; size(x)] );

    % ---------------------------------------------------------------------
    if exculdeEqualPoints
        % this section comes to solve the problem of a plato
        % without this code, points with the same hight will be recognized as peaks
        y = sort(x(:));
        dY = diff(y);
        % finding the minimum step in the data
        minimumDiff = min( dY(dY ~= 0) );   
         adding noise which won't affect the peaks
        x = x + rand(size(x))*minimumDiff;
    end
    % ---------------------------------------------------------------------
    
    
    se = ones(minDist);
    X = imdilate(x,se);
    f = find(x == X);
     

    if nargout
        [varargout{1:nargout}] = ind2sub( size(x), f );
    else
        varargout{1} = f;

    end


http://www.mathworks.com/matlabcentral/fileexchange/14498-local-maxima-minima

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi利用TActionList实现权限控制发布时间:2022-07-18
下一篇:
Delphi Virtual String Tree 基本用法发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap