91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .m
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-16
  • 語言: Matlab
  • 標簽: function??%??

資源簡介

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

評論

共有 條評論