bdry_extract_3.m

来自「提取灰度图的边界」· M 代码 · 共 34 行

M
34
字号
function [x,y,t,c]=bdry_extract_3(V);
% [x,y,t,c]=bdry_extract_3(V);
% compute (r,theta) histograms for points along boundary of single
% region in binary image V

% extract a set of boundary points w/oriented tangents
%sig=1;
%Vg=gauss_sig(V,sig);
Vg=V; % if no smoothing is needed
c=contourc(Vg,[0.5,0.5]);
[G1,G2]=gradient(Vg);

% need to deal with multiple contours (for objects with holes)
fz=c(1,:)~=0.5;
c(:,find(~fz))=NaN;
B=c(:,find(fz));

npts=size(B,2);
t=zeros(npts,1);%加速循环
for n=1:npts
   x0=round(B(1,n));
   y0=round(B(2,n));
   t(n)=atan2(G2(y0,x0),G1(y0,x0))+pi/2;
end
x=B(1,:);
y=B(2,:);

%modified by cwb%
%B1=reshape(B,[2,5,size(B,2)/5]);
%B1=squeeze(sum(B1,2)./5);
%x=B1(1,:);
%y=B1(2,:);

⌨️ 快捷键说明

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