Why my code keep running non stop?
이전 댓글 표시
Hi. I wanna know why my code keep running non stop? There's no error displayed.
image1= getimage(handles.axes1)
bw1=imresize(image1,[128 128])
bw1=rgb2gray(bw1)
%binarization
bw1=im2double(bw1);
bw1 = im2bw(bw1,0.90);
%thinning
BW3=bwmorph(~bw1,'thin',0.9)
%Extracting black pixel
k=1
for i=1:128
for j=1:128
if(BW3(i,j)==0)
u(k)=i
v(k)=j
k=k+1
BW3(i,j)=1
end
end
end
C=[u;v] %the curve of signature
N=k-1 %no of pixel in signature
oub=sum(C(1,:))/N %x coordinate cnter of mass
ovb=sum(C(2,:))/N %y coordinate cnter of mass
%rotate
for i=1:N
u(i)=u(i)-oub+1
v(i)=v(i)-ovb+1
end
%the new curve of signature
C=[u;v]
ub=sum(C(1,:))/N
vb=sum(C(2,:))/N
ubSq=sum((C(1,:)-ub).^2)/N
vbSq=sum((C(2,:)-vb).^2)/N
for i=1:N
uv(i)=u(i)*v(i)
end
uvb=sum(uv)/N
M=[ubSq uvb;uvb vbSq]
minIgen=min(abs(eig(M)))
MI=[ubSq-minIgen uvb;uvb vbSq-minIgen]
theta=(atan((-MI(1))/MI(2))*180)/pi
thetaRad=(theta*pi)/180
rotMat=[cos(thetaRad)-sin(thetaRad);sin(thetaRad)
cos(thetaRad)];
%rotate the signature passing the new coordinate
for i=1;N
v(i)=(C(2,i)*cos(thetaRad))-(C(1,i)*sin(thetaRad))
u(i)=(C(2,i)*sin(thetaRad))+(C(1,i)*cos(thetaRad))
end
C=[u;v]
for i=1;N
u(i)=round(u(i)+oub-1)
v(i)=round(v(i)+ovb-1)
end
mx=0
my=0
if(min(u)<0)
mx=-min(u)
for i=1:N
u(i)=u(i)+mx+1
end
end
if(min(v)<0)
my=-min(v)
for i=1:N
v(i)=v(i)+my+1
end
end
C=[u;v]
for i=1:N
BW3((u(i)),(v(i)))=0
end
xstart=128
xend=1
ystart=128
yend=1
for r=1:128
for c=1:128
if((BW3(r,c)==0))
if(r<ystart)
ystart=r
end
if((r>yend))
yend=r
end
if(c<xstart)
xstart=c
end
if(c>xend)
xend=c
end
end
end
end
for i=ystart:yend
for j=xstart:xend
im((i-ystart+1),(j-xstart+1))=BW3(i,j)
end
end
%display result at axes2
axes(handles.axes2)
imshow(im)
댓글 수: 4
Walter Roberson
2019년 10월 14일
Your code ends when I run it.
I recommend that you learn to put a semi-colon on the end of lines that assign into arrays in a loop, as otherwise you display a lot of information to the screen that likely does not need to be displayed at least until the loop finishes.
Najwa Samlan
2019년 10월 14일
Walter Roberson
2019년 10월 14일
for i=1;N
should be
for i=1:N
Image Analyst
2019년 10월 14일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Segmentation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!