clear all; close all; clc;mainfc;
i=imread('直线在其中.bmp');
I1=i;
[row,range]=size(i);
p=row*range;a=0;Y=zeros(1,p);Q=zeros(1,p);
for k1=1:1:row
for k2=1:1:range
if i(k1,k2)==0
a=a+1;
XXX=k2-1;YYY=row+1-k1;
Y(a)=YYY;Q(a)=YYY-XXX;
end
end
end
% for t=1:1:a
% o=[Y(t) Q(t)]
% end
X1=[0 1];Y1=[Y(1) Q(1)];
%plot(X1,Y1,'r');hold on;
YY=zeros(1,a-1);QQ=zeros(1,a-1);
for t=2:1:a
X2=[0 1];Y2=[Y(t) Q(t)];
%plot(X2,Y2);
[YY(t-1),QQ(t-1)]=pll(X1,Y1,X2,Y2);
% yyy=YY(t-1)
% qqq=QQ(t-1)%看交点
%plot(YY(t-1),QQ(t-1),'ko');
end
[rhao]=the_max1(YY,QQ,QQ);
mainfc;
i1=ones(row,range);
rhao
t2=rhao(1);t3=rhao(2);
t2=round(t2);t3=round(t3);
% t2=1.5;t3=1.5;
for k1=1:1:row
for k2=1:1:range
XXX=k2-1;YYY=row+1-k1;
if abs(YYY-(t2*XXX+t3))<=1%YYY==t2*XXX+t3
i1(k1,k2)=0;
end
end
end
imwrite(i1,'找出的直线.bmp','bmp');
i2=imread('找出的直线.bmp');
figure;
subplot(1,2,1);
imshow(I1);
title('原图');
subplot(1,2,2);
imshow(i2);
title('检测图');
%