资源简介
function B=boundaries(BW,conn,dir) %输入二值图像,跟踪二值目标轮廓
代码片段和文件信息
function B=boundaries(BWconndir)%目标的边缘跟踪
%BOUNDARIES Trace object boundaries.
%B=BOUNDARIES(BW) traces the exterior boundaries of objects in the binary
%image BW. B is a P-by-1 cell array where P is the number of objects in
%the image. Each cell contains a Q-by-2 matrix each row of which contains
%the row and column coordinates of a boundary pixel. Q is the number of
%boundary pixels for the corresponding object. object boundaries are traced
%in the clockwise direction.
%
%B=BOUNDARIES(BWCONN) specifies the connectivity to use when tracing
%boundaries. CONN may be either 8 or 4. The default value for CONN is 8.
%
%B=BOUNDARIES(BWCONNDIR) specifies the direction used for tracing
%boundaries. DIR should be either ‘cw‘(trace boundaries clockwise) or
%‘ccw‘(trace boundaries counterclockwise). If DIR is omitted BOUNDARIES
%traces in the clockwise direction.
if nargin<3
dir=‘cw‘;
end
if nargin<2
conn=8;
end
L=bwlabel(BWconn);
%The number of objects is the maximum value of L. Initializethe cell array
%B so that each cell initially contains a 0-by-2 matrix.
numobjects=max(L(:));
if numobjects>0
B={zeros(02)};
B=repmat(Bnumobjects1);
else
B={};
end
%Pad lable matrix with zeros. This lets us write the boundary-following
%loop without worrying about going off the edge of the image.
Lp=padarray(L[1 1]0‘both‘);
%Compute the linear indexing offsets to take us from a pixel to its
%neighbors.
M=size(Lp1);
if conn==8
%Order is N NE E SE S SW W NW.
offsets=[-1M-1MM+11-M+1-M-M-1];
else
%Order is N E S W.
offsets=[-1M1-M];
end
%next_search_direction_lut is a lookup table. Given the direction from pixel k to pixel k+1 what is the direction to start with when examining the neighborhood of pixel k+1?
if conn==8
next_search_direction_lut = [8 8 2 2 4 4 6 6];
else
next_search_direction_lut= [4 1 2 3];
end
%next_direction_lut is a lookup table. Given that we just looked at
%neighbor in a biven direction which neighbor do we look at next?
if conn==8
next_direction_lut = [2 3 4 5 6 7 8 1];
else
next_direction_lut= [2 3 4 1];
end
%Values used for marking the starting and boundary pixels.
START = -1;
BOUNDARY= -2;
%initialize scratch space in which to record the boundary pixels as well as
%follow the boundary.
scratch =zeros(1001);
%Find candidate starting locations for boundaries.
[rrcc]=find((Lp(2:end-1:)>0)&(Lp(1:end-2:)==0));
rr=rr+1;
for k=1:length(rr)
r=rr(k);
c=cc(k);
if (Lp(rc)>0)&(Lp(r-1c)==0)&isempty(B{Lp(rc)})
%We‘ve found the start of the next boundary. Compute its linear
%offset r
相关资源
- pettittFunctionUser.m
- 使用S-Function函数实现离散PID控制器,
- kernel function_matlab
- SMO_matlabfunction.rar
- SVM function available 可实现SVM函数曲线拟
- matlab 用于核pca(KPCA)的库函数
- S-Function编写指导及.zip
- matlab S-function 编写的离散状态空间表
- function Energy Efficiency
- 阵列信号处理(Array-signal-function)的
-
Sfunction_ADRC-_Simuli
nk 基于S函数编写了 - IPSO-FOR-FUNCTION 改进的粒子群优化算法
- PR_FUNCTION_TEST 比例谐振控制器功能性验
- CPSO-FOR-function 小生境遗传粒子群混合
- Image-evaluation-function-matlab 包含九种图
- matlab开发-FastFFTFunction
- ADRC的m函数版本,离散化后的公式,用
- svpwm的s函数
- 训练BP神经网络拟合函数曲线
评论
共有 条评论