clc;
clear all;
close all
%global hit123;
m=imread('C:\Users\Administrator\Desktop\遥感数字图像\道路提取\道路提取\hit321.tif');
% subplot(2,2,1),
%imshow(I);
%title('原始图像');
figure(1);
%subplot(121);
imshow(m);
fr=m(:,:,1);
fg=m(:,:,2);
fb=m(:,:,3);
for i=1:1492
for j=1:1476
if (fr(i,j)>(fg(i,j)+15))&((fb(i,j)>fg(i,j)+10));
fg(i,j)=0;
fr(i,j)=0;
fb(i,j)=0;
end
end
end
m(:,:,2)=fg;
m(:,:,1)=fr;
m(:,:,3)=fb;
for i=1:1492
for j=1:1476
if (fg(i,j)-fr(i,j)>20);
fg(i,j)=0;
fr(i,j)=0;
fb(i,j)=0;
end
end
end
m(:,:,2)=fg;
m(:,:,1)=fr;
m(:,:,3)=fb;
J=rgb2gray(m);
%J=imadjust(J,[76/184 172/184],[]);
figure(2)
%subplot(122);
imshow(J);
%imshow(J);
I=(J<165)&(J>125);
%[riverRow riverCol]=find(I==0);
H=I;
figure(3);
imshow(H);
%A=2:1491;
%B=2:1475;
% C1(A ,B)=I1(A-1,B-1)+2*I1(A,B-1)+I1(A+1,B-1)-I1(A-1,B+1)-2*I1(A,B+1)-I1(A+1,B+1);
figure(4)
B=[0 1 0;1 1 1;0 1 0];
%C1=~C1ow,
%C1(riverRow,riverCol)=0;
%C1=~C1;
C1=H;
se=[0 0 1 0 0;
0 0 1 0 0;
1 1 1 1 1;
0 0 1 0 0;
0 0 1 0 0];
Se=strel('square',5');%方型结构元素
%se=strel('disk',5');%圆盘型结构元素
%C1=imerode(C1,B);
C1=imerode(C1,B);
imshow(C1);
% q=imdilate(C1,B);
% q=imdilate(q,B);
%imerode
figure(8);
C1=imopen(C1,B);
%C1=imopen(C1,B);
imshow(C1);
figure(9);
%C1=imerode(C1,B);
%C1=imdilate(C1,B);
%C1=imerode(C1,B);
%C1=imdilate(C1,B);C1=imerode(C1,B);
% C1=imdilate(C1,B);C1=imerode(C1,B);
C1=imdilate(C1,B);
imshow(C1);
%{
e=strel('square',4);
C4=C1;
k=[1 1;1 1];
I2=C1;
%I1=imdilate(I1,k);
%I1=imerode(I1,se);
%imshow(I1);
figure(11);
%SE = strel('rectangle', [60,3]);
SE = strel('line', 80,0);
%C1=imdilate(I2,SE);
C1=imerode(C1,SE);
imshow(C1);
figure(12);
%ME= strel('rectangle', [3,60]);
ME = strel('line', 80,90);
%M1=imdilate(I2,ME);
M1=imerode(M1,ME);
imshow(M1);
figure(13);
%I1=imerode(I1,SE)
A=2:1491;
B=2:1475;
% C1= C1|M1;
%I1(A ,B)=I(A-1,B-1)+2*I(A,B-1)+I(A+1,B-1)-I(A-1,B+1)-2*I(A,B+1)-I(A+1,B+1);
%I1=~I1;
B=[0 1 0;1 1 1;0 1 0];
C1=imreconstruct(H,C4);
imshow(C4);
figure(14);
C4=imerode(C4,se);
C1=imreconstruct(H,C4);
% C4=imdilate(C4,B);
imshow(C4);
%}
%C1=imopen(C1,se);
%C1=imerode(C1,B);
%K2_1=edge(uint8(C1),'canny');
%K2_1=uint8(C1);
%figure(10);
K2_1=C1;
C2=K2_1;
X=C2(:,1:260);
X=imerode(X,B);%C1(C1,B);
r1=[-30:-25];
[H1,T1,R1]=hough(X,'RhoResolution',12);
peaks=houghpeaks(H1,12);
lines=houghlines(X,T1,R1,peaks);
%{
imshow(C1);title('x');
[H1,T1,R1]=hough(K2_1,'RhoResolution',2,'ThetaResolution',0.1);
peaks=houghpeaks(H1,8);
lines=houghlines(K2_1,T1,R1,peaks);
figure(11);
%imshow(K2_1);
imshow(C1);
hold on;
for i=1:length(lines)
xy=[lines(i).point1;lines(i).point2];
plot(xy(:,1),xy(:,2),'LineWidth',4);
end
%}
figure(12);
m=imread('C:\Users\Administrator\Desktop\遥感数字图像\道路提取\道路提取\hit321.tif');
imshow(m);
hold on;
for i=1:length(lines)
xy=[lines(i).point1;lines(i).point2];
plot(xy(:,1),xy(:,2),'LineWidth',4);
end
Y0=zeros(1492,260);
Y5=C2(:,261:1476);
Y=[Y0 Y5];
[H1,T1,R1]=hough(Y,'RhoResolution',8,'ThetaResolution',0.1);
peaks=houghpeaks(H1,8);
lines=houghlines(Y,T1,R1,peaks);
%figure;
%imshow(Y);
hold on;
for i=1:length(lines)
xy=[lines(i).point1;lines(i).point2];
plot(xy(:,1),xy(:,2),'LineWidth',4);
end
hold off;
figure(13);
imshow(X);
figure(14);
imshow(Y5);