Project Report
Project Report
Project Report
Guide: Prof. Cornelia Fermuller
Yash Shah
UID: 115710498
1|Page
Project 1: Lane Detection Yash Shah
Contents
Extrapolation of Lines...................................................................................... 15
Conclusion………………………………………………………………………………………………………17
2|Page
Project 1: Lane Detection Yash Shah
Lane Detection
In this project, MATLAB is used as an Image Processing Tool to detect Lanes on the road. The
following techniques are used for lane detection.
• Color Masking
• Canny Edge Detection
• Region of Interest Selection
• Hough Transform Line detection
%==========================================================================
%==========================================================================
Output_Video=VideoWriter('Result_Yash');
Output_Video.FrameRate= 25;
open(Output_Video);
3|Page
Project 1: Lane Detection Yash Shah
First the frame is read and them filtered using a Gaussian Filter.
while hasFrame(VideoFile)
frame = imgaussfilt3(frame);
figure('Name','Filtered Image'), imshow(frame);
4|Page
Project 1: Lane Detection Yash Shah
The frame is masked with yellow and white color to detect the lane lines perfectly.
5|Page
Project 1: Lane Detection Yash Shah
Edge Detection
In this section, edges are obtained from the masked image and closed edges with smaller areas are
neglected.
6|Page
Project 1: Lane Detection Yash Shah
frameY = bwareaopen(frameY,15);
frameW = bwareaopen(frameW,15);
7|Page
Project 1: Lane Detection Yash Shah
% figure(1)
% imshow(frame);
% [r c] = ginput(10);
8|Page
Project 1: Lane Detection Yash Shah
Hough Transform
In this section I have used the hough function to get the hough transfrom of the binary edge
detected image, which gives us the hough values and then I have plotted the hough plot as shown
in the figure below.
[H_Y,theta_Y,rho_Y] = hough(frame_roiY);
9|Page
Project 1: Lane Detection Yash Shah
[H_W,theta_W,rho_W] = hough(frame_roiW);
P_Y = houghpeaks(H_Y,2,'threshold',2);
P_W = houghpeaks(H_W,2,'threshold',2);
imshow(imadjust(rescale(H_W)),[],'XData',theta_W,'YData',rho_W,'InitialMagnification',
'fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal
hold on
colormap(gca,hot)
x = theta_W(P_W(:,2));
y = rho_W(P_W(:,1));
plot(x,y,'s','color','blue');
hold off
imshow(imadjust(rescale(H_Y)),[],'XData',theta_Y,'YData',rho_Y,'InitialMagnification',
'fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal
hold on
colormap(gca,hot)
x = theta_W(P_Y(:,2));
y = rho_W(P_Y(:,1));
plot(x,y,'s','color','blue');
hold off
lines_Y = houghlines(frame_roiY,theta_Y,rho_Y,P_Y,'FillGap',3000,'MinLength',20);
10 | P a g e
Project 1: Lane Detection Yash Shah
lines_W = houghlines(frame_roiW,theta_W,rho_W,P_W,'FillGap',3000,'MinLength',20);
max_len = 0;
for k = 1:2
xy = [lines_W(k).point1; lines_W(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
11 | P a g e
Project 1: Lane Detection Yash Shah
Extrapolation of Lines
In this section the lines that are found in hough lines are extrapolated on the main filtered image.
12 | P a g e
Project 1: Lane Detection Yash Shah
% right_plot = rightp1;
% left_plot = leftp1;
slopeL = (left_plot(2,2)-left_plot(1,2))/(left_plot(2,1)-left_plot(1,1));
slopeR = (right_plot(2,2)-right_plot(1,2))/(right_plot(2,1)-right_plot(1,1));
13 | P a g e
Project 1: Lane Detection Yash Shah
Turn Prediction
In this section, I have predicted where to turn by looking at the vanishing point found from the
extrapolated lines.
%------------------Turn Prediction---------------
14 | P a g e
Project 1: Lane Detection Yash Shah
figure('Name','Final Output')
imshow(frame);
hold on
plot([xLeftY, xRightY], [yLeftY, yRightY], 'LineWidth',8,'Color','red');
plot([xLeftW, xRightW], [yLeftW, yRightW], 'LineWidth',8,'Color','red');
text(650, 65, direction,'horizontalAlignment', 'center',
'Color','red','FontSize',20)
patch('Faces', number, 'Vertices', points,
'FaceColor','green','Edgecolor','green','FaceAlpha',0.4)
hold off
15 | P a g e
Project 1: Lane Detection Yash Shah
Conclusion
The project was successful in that the video images clearly show the lane lines are detected
properly and lines are very smoothly handled.
It only detects the straight lane lines. It is an advanced topic to handle curved lanes (or the curvature
of lanes). We'll need to use perspective transformation and also poly fitting lane lines rather than
fitting to straight lines.
16 | P a g e