⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findvalley.m

📁 寻找积分投影直方图的谷集并标识出来
💻 M
字号:
% 
% vly = findValley(hist2D,threshValley)
% 功能: 搜索2值灰度图像的水平积分投影图的谷集
% 算法:
%       1.获取可能谷值集--投影高度升序的前n个(山谷的高度极小);
%       2.谷值集筛选:(1)山谷特性---两边坡高,中间谷底低。 
%                    (2)消除伪谷底--两谷之间有一定距离(夹着山峰)。
% 参数:
%       hist2D        -- 2D矩阵:图像(纵向)高度(像素数)-- 水平(x轴向)投影。
%       threshValley  -- 山谷宽度阈值,用于判断山谷真伪,有山峰的梯度(陡峭)决定。
%       vly           -- 山谷集(序号(相对位置)、绝对位置(灰度级x、积分投影值)、)
% Example:  求函数sin(xx)+xx/2的谷集
%      %----测试数据集生成-----
%      xx=-2*pi:0.2:2*pi;
%      yy=sin(xx)+xx/2;
%      data2D=[xx;yy];
%      valley=findValley(data2D,2), % 命令窗口显示valley谷集
%      %----曲线sin(xx)+xx/2谷集图示-----
%      figure; 
%      m=size(yy);
%      hold on;
%      plot(valley(2,:),valley(3,:),'r*');
%      plot(xx,yy,'c.');
%      legend('谷集');  %------?!!!还要整理-legend、title字体,颜色,位置,标识符-- 
%      title('曲线sin(xx)+xx/2谷集图示');     
%      hold off;
function vly = findValley(hist2D,threshValley)
% 函数内部测试数据显示 注释掉函数头,去掉19-22行的注释符   
% clear all; clc;
% x=-2*pi:0.2:2*pi;
% histVector=sin(x)+cos(x)+x/3;
% threshValley=2;
histVector=hist2D(2,:);
rowcol=size(histVector);
top=rowcol(2);         % col(2)/3*2;
bottom=1;              % col/2;
jb=bottom+threshValley*3+1;jt=top-threshValley*3-1;
vly=[];
height= sort(histVector);    %  投影高度histVector排序
%for i=1:(top-bottom)/8   
for i=1:(top-bottom)
%for i=1:4 
    for j=jb:jt        
        if histVector(j)==height(i)
            f=j;
            while (histVector(j+1)==histVector(j)) & (j< (top-threshValley*3-1))    
               j=j+1;
            end
            ls=f-threshValley*3;   % left slope     
            lv=f-threshValley;   % the left side of the valley
            rv=j+threshValley;   % the right side of the valley
            rs=j+threshValley*3;   % right slope            
            lH=sum(histVector(ls-1:lv-1));
            vH=sum(histVector(lv:rv));
            rH=sum(histVector(rv+1:rs+1));
            if vH<lH & vH<rH                   
                %  测试数据显示    
                %  [i f y(f-2:f+2)],
                %  [ ls lv rv rs],
                %  [lH vH rH],
                %  vly,
                %  f=j;
                  
                  %----------------------消除谷的重复统计-----------------------         
                   m=size(vly);
                   m=m(2);      %获得已有谷数      
                   flag=0;    
                   for t=1:m
                     if  abs(f-vly(1,t))<=threshValley*2  % f是否属于已有的山谷 
                         flag=1;     
                     end
                   end
                   if flag==0                      % f是独立的山谷,加入谷集 
                       vv=[f ; hist2D(:,f)];
                       vly=[vly vv];
                   end
                  %--------------------------- 消除谷的重复统计-----------------
               end    %end  %if_end 
        end  % if
    end    % for    
end % for

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -