0
$\begingroup$

I am truly sorry if my question sounds little bit stupid, but I am getting stuck at this part for a long time. I am currently working for my final year project of lane detection for curved road using B-snake. I am using Matlab software, and I have done the image pre processing part by converting the RGB value to grayscale. After the converting I simply use the Canny edge detection but it seems that there is too many noise.

The original image

This is the first part that I obtained :

Image of Canny edge detection

Then, I tried the region props function for which the Matlab code I obtained from this website. The noise has reduced a little bit.

enter image description here

The only region that I want is the road region. But I don't manage to get the ROI that I need. So I just proceed to Hough Transform to obtain the straight line. I try to run the coding of Hough Transform that I found on the internet, but the result is so confusing. I don't know how to change the code so that my result will turn out better.

The image after Hough Transform is applied :

enter image description here

This is my full code:

I=imread('C:\Users\LENOVO\Documents\MATLAB\PSM2\road\draw\test1.jpg'); %         Input image file here
dim = size(I); % Get size of the image and store in an array called 'dim'.%size array matrix; 1 is height, 2 is width

I2 = rgb2gray(I); % Convert to grayscale
BW = edge(I2,'canny',[]); % Edge detection using Canny
cc = bwconncomp(BW);
I4 = labelmatrix(cc);

a_rp = regionprops(cc,'Area','MajorAxisLength','MinorAxislength','Orientation','PixelList','Eccentricity');
idx = ([a_rp.Eccentricity] > 0.99 & [a_rp.Area] > 100 & [a_rp.Orientation] < 60 & [a_rp.Orientation] > -90);

BW2 = ismember(I4,find(idx));
[H,T,R] = hough(BW2);

%  figure, imshow(H,[], 'XData', T, 'YData', R, 'InitialMagnification', 'fit');
%  xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P  = houghpeaks(H,50,'threshold',ceil(0.1*max(H(:))));

% Set houghpeaks parameters, threshold unsure
x = T(P(:,2));
y = R(P(:,1));
plot(x,y,'s','color','white');

% Apply median filtering
I3 = medfilt2(I2);

% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',20,'MinLength',10);
figure, imshow(I3),imagesc(I3), 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','yellow');
    plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end

showlines = struct(lines);
cellData = struct2cell(showlines);

% X-coordinates are for width
% Y-coordinates are for height
%point1(x y) etc

for i = 1:280
    % 'A' stores all 'x' coordinates of point 1
    A([i,i+1])= [cellData{1,i}];
    % 'B' stores all 'x' coordinates of point 2
    B([i,i+1])= [cellData{2,i}];
    % 'C' stores all 'y' coordinates of point 1
    C([i,i])= [cellData{1,i}];
    % 'D' stores all 'y' coordinates of point 2
    D([i,i])= [cellData{2,i}];
end

I do really hope someone can help me. At least general idea for me to proceed to the next step is enough. Thank you in advance.

$\endgroup$
  • $\begingroup$ In my humble opinion, your approach won't easily lead to good result. If I were you I would first try to segment the images into road and non-road part. Once you have the road part, which is a very smooth texture, it will be easy to get only the white lanes. You could even start by detecting the white lane. You have a lots of a priori on these things, you know that the road will be approximatively grey, and in the foreground, and in the lower part of your images. You know that the white marking will be ... white and on the road. $\endgroup$ – Antoine Bassoul Apr 24 '15 at 7:38
  • $\begingroup$ @ sheeha66 How did you fix these problem. Can you please share the updated code. nithinramachandran24@gmail.com $\endgroup$ – Nithin M R Dec 13 '16 at 10:44
1
$\begingroup$

Following my comment I suggest you a "dumb" heuristic you could try : Consider your images row-wise. Extract a few features from each row, these could be average RGB value, RGB covariance matrix, entropy etc ... Use a simple clustering algorithm to separate your image into 2 parts : the upper one and the lower one. Let's assume the heuristic has been successful and the lower part is mostly composed of road. We'll just consider this part and run a clustering algorithm on the RGB values. We keep the number of cluster low and we want to take the cluster which is the closest from grey as the road cluster. Once you have a not too bad road segmentation, play around a bit with edge detection to extract only the white marking.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.