A=imread(filename);
subplot(2,2,1);
imshow(A);
[N,M]=size(A);
% A= bwmorph(A,'thin');
%A=im2bw(A);
X=zeros(1);%%%行
Y=zeros(1);%%%列
i=1;
j=1;
for n=1:N
for m=1:M
if (A(n,m)~=0)
X(:,i)=n;
i=i+1;
break
end
end
end
for m=1:N
for n=1:M
if (A(n,m)~=0)
Y(:,j)=m;
j=j+1;
break
end
end
end
[x1,x2]=size(X);
[y1,y2]=size(Y);
a1=X(:,1);
a2=X(:,x2);
a3=Y(:,1);
a4=Y(:,y2);
A1=A(a1:a2,a3:a4);%%%框定數字
subplot(2,2,2);
imshow(A1);