码迷,mamicode.com
首页 > 其他好文 > 详细

一维曲线极值检测

时间:2015-12-10 11:21:38      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

 

二维存储的一维曲线极值检测程序

clc;clear;close all;
BW1 = imread(‘BW1.BMP‘);
figure,imshow(BW1,[]);

% 提取图像中的曲线
[M,N] = size(BW1);
x=[];y=[];
j=1;
while j<=N,
    for i = 1 : M
     try
        if BW1(i, j) == 1
          x = [x, N - j]; %#ok<*AGROW>
          y = [y, M - i];
          j=j+1;
          break;
        end
     catch
        fprintf(1,‘%d, %d\n‘,i,j);
     end
    end
end


xx = max(x) : -0.1 : min(x);
yy = interp1(x, y, xx, ‘linear‘); % 一维数据插值cublic
x = xx;
y = yy;
N = size(y, 2);
y(N) = y(N - 1) + 1;
left = 1;
right = 0;
Sk = 0; % 0:斜率未知,1:上升,-1:下降
peak = [];

for j = 2 : N,
    if Sk == 0
        if (y(j) <= y(j - 1))
            Sk = 0;          % 下降及保持信号、初始信号
            continue;
        else
            Sk = 1;          % 上升信号
            left = j;
            continue;
        end;
    end;
    
    if (Sk == 1)
        if (y(j) < y(j - 1))
            Sk = -1;         % 下降信号
            continue;
        end       
    else if (Sk == -1)
            if (y(j) < y(j - 1))
                right = j;
            end;
            if (y(j) > y(j - 1))
                Sk = 0;
                disp([left, right]);
                peak = [peak; left, right];
                continue;
            end           
        end     
    end
    
    if Sk == 0
        if (y(j) <= y(j - 1))
            Sk = 0;
            continue;
        end;
        if (y(j) > y(j - 1))
            Sk = 1;
            left = j;
            continue;
        end;
    end;    
end;

% 画出峰值
figure,
plot(y);
hold on;
[M,N] = size(peak);
for j = 1 : M
    minP = min(peak(j, 1), peak(j, 2));
    maxP = max(peak(j, 1), peak(j, 2));
    [C, I] = max(y(minP : maxP));
    plot([minP + I, minP + I], [0, C], ‘g‘);
end;

 

 

技术分享

 

技术分享

 

参考, pund, getMultiPeak.m

一维曲线极值检测

标签:

原文地址:http://www.cnblogs.com/arxive/p/5035183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!