📄 digis1.m
字号:
function [x,y,varargout]=digis1(alfa,varargin);
%[a b]=digis1(alfa) - alfa - string, name of
%image file with spot or 2D-array, or 3D array
%(color).
%a,b - vectors of curve (spot border) coordinates;
%[a,b,c]=digis1(...) - c - vector 1x14:
%c(1:2) - coordinates of center of mass of curve,
%c(3:4) - coordinates of center of mass of spot,
%c(5)- count of pixels of border,
%c(6) - count of pixels of spot,
%c(7:8) - a(c(7)),b(c(7)),a(c(8)),b(c(8)) -
% coordinates of the most remote points,
%c(9) - a distance between them,
%c(10:13) - coordinates of ends of diagonal of
% of minimal rectangle which contains a spot
% (sides of rectangle are parallel to axes),
%c(14) - perimeter (count of external edges
% of border pixels),
%c(15) - perimeter (length of line connected
%centers of border pixels),
%digis(alfa,a1), a1=1 - to use clean procedure,
%digis(alfa,a1,a2) - a2 - a threshold for
%binarization, default is mean intensity value,
%digis(alfa,a1,a2,a3), a3 - is maximal number
%of iterations, default is 10000.
%E x a m p l e
%ax=zeros(100);
%ax(20:end,50:end)=1;
%[a b xc]=digis1(ax);subplot(1,2,1);
%zx=plot(a,b,'-',xc(1),xc(2),'+',xc(3),xc(4),'*');
%subplot(1,2,2);
%imshow(ax);colormap([0 0 0;1 1 1]);axis xy
a1='It is impossible to complete path tracing .';
a2='Include ray deletion option and try once more.';
v=0; q=0; per=0; qint=[];
qnt=40; qnn=0; dk1=0; dk2=0;
k=1; kt=k; dg1=1; thre=[];
J=alfa; v1=1; pr=0;
if ischar(alfa)
J=imread(alfa);
end
if isvector(J)
error('Input data set is neither 2D nor 3D array');
end
lensj=length(size(J));
I=J;
if lensj==3
I=double(J(:,:,1))*0.298936+double(J(:,:,2))*0.587043+double(J(:,:,3))*0.114021;
end
switch nargin
case 1
case 2
qnn=varargin{1};
case 3
qnn=varargin{1};
thre=varargin{2};
case 4
qnn=varargin{1};
thre=varargin{2};
qint=varargin{3};
otherwise
error('invalid input')
end
if isempty(thre)
thre=mean(mean(I));
end
if isempty(qint)
qint=10000;
end
I(I<thre)=0;
I=logical(I);
x=[]; y=[]; [si,sj]=size(I);
if qnn~=0
disp('Cleaning')
I=cleanrays(I);
disp('Cleaning finished')
end
if sum(sum(~I))==0
error('No spot detected')
end
%first black search
[i,i]=max((max(I==0)));
[j j]=max(I(:,i)==0);
x=[x j]; y=[y i];
xb=x; yb=y;
%Right and Up
v0130;
v0300;
v0430;
while 1
dg1=dg1+1;
if dg1>qint
sss=['Maximal number of iterations ',num2str(qint),' is exceeded.'];
if (x(k)~=xb)&(y(k)~=yb)
ssss='End point is not coincided with starting one.';
sss={sss,ssss};
end
warndlg(sss);
break
end
v3=0;
while v==1
v1030;%'v==1'
if (x(k)==xb)&(y(k)==yb)|v>1,break,end
v0130;
if v>1,break, end
v0300;
if v>1,break, end
v0430;
if v>1,break, end
v0730;
if (x(k)==xb)&(y(k)==yb)|v>1,break,end
v0900;
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
v3=v3+1;
end %%1
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==2
v1200; %'v==2'
if (x(k)==xb)&(y(k)==yb)|v~=2,break,end
v0300;
if v~=2,break,end
v0430;
if v~=2,break,end
v0600;
if v~=2,break,end
v0900;
if (x(k)==xb)&(y(k)==yb)|v~=2,,break,end
v1030;
if v3>qnt, break, end
v3=v3+1;
end %%2
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==3
v0130;%'v==3'
if v~=3,break,end
v0430;
if v~=3,break,end
v0600;
if v~=3,break,end
v0730;
if (x(k)==xb)&(y(k)==yb)|v~=3,,break,end
v1030;
if v~=3,break,end
v1200;
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
v3=v3+1;
end %%3
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==4
v0300;
if v~=4,break,end
v0600;
if v~=4,break,end
v0730;
if (x(k)==xb)&(y(k)==yb)|v~=4,break,end
v0900;
if (x(k)==xb)&(y(k)==yb)|v~=4,break,end
v1200;
if (x(k)==xb)&(y(k)==yb)|v~=4,break,end
v0130;
if v3>qnt, break, end
v3=v3+1;
end %%4
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==5
v0430; %'v==5'
if v~=5,break,end
v0730;
if (x(k)==xb)&(y(k)==yb)|v~=5,break,end
v0900;
if (x(k)==xb)&(y(k)==yb)|v~=5,break,end
v1030;
if v~=5,break,end
v0130;
if v~=5,break,end
v0300;
if v3>qnt,break,end
v3=v3+1;
end %%5
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==6
v0600;%'v==6'
if (x(k)==xb)&(y(k)==yb)|v~=6,break,end
v0900;
if (x(k)==xb)&(y(k)==yb)|v~=6,break,end
v1030;
if v~=6,break,end
v1200;
if (x(k)==xb)&(y(k)==yb)|v~=6,break,end
v0300;
if v~=6,break,end
v0430;
if v3>qnt,break,end
v3=v3+1;
end %%6
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==7
v0730; %'v==7'
if (x(k)==xb)&(y(k)==yb)|v~=7,break,end
v1030;
if (x(k)==xb)&(y(k)==yb)|v~=7,break,end
v1200;
if v~=7,break,end
v0130;
if v~=7,break,end
v0430;
if v~=7,break,end
v0600;
if v3>qnt,break,end
v3=v3+1;
end %%7
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
while v==8
v0900; %'v==8'
if (x(k)==xb)&(y(k)==yb)|v~=8,break,end
v1200;
if (x(k)==xb)&(y(k)==yb)|v~=8,break,end
v0130;
if v~=8,break,end
v0300;
if v~=8,break,end
v0600;
if v~=8,break,end
v0730;
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
v3=v3+1;
end %%8
if (x(k)==xb)&(y(k)==yb)|v3>qnt,break,end
dk=k-kt;
if dk==dk1
dk2=dk2+1;
else
dk2=0;
end
if (dk==dk1)&(dk2>qnt)
wd=warndlg('Infinite looping','Computing is over');
set(wd,'Color', [0.831373 0.815686 0])
'Infinite looping'
break
end
dk1=dk;
kt=k;
end %dg1
if v3>qnt
warndlg({a1;a2},'Computing is over')
end
cmssn;
% if v==7|v==1
% per=per+1+ind;
% end
varargout(1)={[xc yc xcc ycc length(x)-1 mss ...
uz kz2 kz1 mnx mny mxx mxy per pr]};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -