我做过Sobel和Hough变换,但我找不到实际的结果。我已经分享了我的代码和相应的输出。最终的结果并不令人满意。我需要3行;道路线和车道线也在(中间)。
输入图片
检测线
clear all
clc
I=imread('22roi.jpg');
%I = imdilate(I,strel('disk',1));
[ga] = RGBThreshold(I,[175 175 175]);
gg = imdilate(ga,strel('disk',1));
gg=imfill(gg,'holes');
c=edge(gg,'sobel');%sobel
figure,imshow(gg);
%figure,imshow(c);
[H,T,R]=hough(c);
figure,imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'),ylabel('\rho');
axis on,axis normal,hold on;
P=houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x=T(P(:,2));y=R(P(:,1));
plot(x,y,'s','color','white');
% houghlines
lines=houghlines(c,T,R,P,'FillGap',10,'MinLength',7);
%figure,imshow(I);
figure,imshow(c),hold on;
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','red');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','green');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','green');
% figure,imshow(I);
figure, hold on;
max_len=0;
for k=1:6
xy=[lines(k).point1;lines(k).point2];
%figure,imshow(I);
plot(xy(:,1,:),-xy(:,2),'LineWidth',3,'color','green');
end