Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Lane Detection

Subject: Lane Detection

From: Priti

Date: 21 Sep, 2009 18:26:04

Message: 1 of 6

So I'm not very familiar with MATLAB, and need to help my prof with lane detection in video clips of various test conditions.

I am using the following the article is as my starting guide:
http://www.mathworks.com/matlabcentral/fx_files/10207/1/content/Introduction%20to%20MATLAB%207/Demos/LaneMarkings/html/lanemarkings.html#1

However, i recieve an error message when I get to:
%... then another function to find the boundaries of all the objects in the image. Then we display those in green.
[B,L] = bwboundaries(binary,'noholes');

The error is something about an iptcheckinput.

Please help.

Subject: Lane Detection

From: ImageAnalyst

Date: 21 Sep, 2009 19:18:30

Message: 2 of 6

On Sep 21, 2:26 pm, "Priti " <shah.pr...@gmail.com> wrote:
> So I'm  not very familiar with MATLAB, and need to help my prof with lane detection in video clips of various test conditions.
>
> I am using the following the article is as my starting guide:http://www.mathworks.com/matlabcentral/fx_files/10207/1/content/Intro...
>
> However, i recieve an error message when I get to:
> %... then another function to find the boundaries of all the objects in the image. Then we display those in green.
> [B,L] = bwboundaries(binary,'noholes');
>
> The error is something about an iptcheckinput.
>
> Please help.

---------------------------------------------------------------------------------------------------
The help says this:
BW can be logical or numeric and it must be real, two-dimensional, and
nonsparse. L and N are double. A is sparse logical.
Can you say that your "binary" variable (what they call BW and you
call binary) satisfies these constraints?
Probably not, since it apparently it thinks there is SOMETHING wrong
with your "binary" variable.
If so, then a more complete error message would help.

Subject: Lane Detection

From: Priti

Date: 23 Sep, 2009 22:14:05

Message: 3 of 6

I'm now using MATLAB 7.8.9 (R2009a). The errors are embedded in the code.

>> clear
>> street1 = imread('street1.jpg');
>> imagesc(street1); shg
>> scaled=street1*1.2;
>> image(scaled);
>> level = 220;
>> binary = scaled>level;
>> imagesc(binary);
>> binary = bwareaopen(binary,100);
??? Undefined function or method 'bwareaopen' for input arguments of type
'double'.
 
>> imagesc(binary)
>> hold on
>> %... then another function to find the boundaries of all the objects in the image. Then we display those in green.
[B,L] = bwboundaries(binary,'noholes');
??? Undefined function or method 'bwboundaries' for input arguments of type
'char'.
 
>> % Plot boundaries
for K=1:length(B)
    boundary = B{K};
h(K)=plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);
end
??? Undefined function or variable 'B'.
 
>> % Extract statistics
stats = regionprops(L,'MajorAxisLength','MinorAxisLength');
??? Undefined function or variable 'L'.
 
>> lanes=findlanes(B,h,stats);
??? Undefined function or variable 'B'.
 
>> hold off;
>> imagesc(street1);
hold on
>> for K = 1:length(lanes)
    plot(lanes{K}(:,2), lanes{K}(:,1), 'g', 'LineWidth', 2)
end
hold off
??? Undefined function or variable 'lanes'.
 
>>

Subject: Lane Detection

From: ImageAnalyst

Date: 23 Sep, 2009 23:49:05

Message: 4 of 6

Priti:
Try this code. It's essentially yours but with a standard MATLAB demo
image (a monochrome tif image). It runs just fine with no errors at
all. Of course I didn't do the last part because I don't have your
custom findlanes() function, but the built-in MATLAB functions that
you said you have problems with run flawlessly. Just copy and paste
this code, fix any line breaks introduced by the newsreader program,
and run it. If you get any errors with this (you shouldn't), then
report back.

clc;
close all;
clear all;
workspace;
% Read in standard MATLAB demo image
street1 = imread('cameraman.tif');
subplot(2, 3, 1);
imshow(street1, [0 255]);
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.
title('Original Image');

scaled=street1*1.2;
subplot(2, 3, 2);
imshow(scaled, [0 255]);
title('Scaled Image');

thresholdValue = 100;
binaryImage = scaled > thresholdValue;
subplot(2, 3, 3);
imshow(binaryImage, []);
title('Binarized Image');

binary2 = bwareaopen(binaryImage, 1500);
subplot(2, 3, 4);
imshow(binary2, []);
title('Morphologically Opened Image');
uiwait(msgbox('Note the shirt collar, tripod mount, and camera clutter
have been removed.'));

[B, labeledImage] = bwboundaries(binary2,'noholes');
subplot(2, 3, 5);
imshow(labeledImage, []);
title('Labeled Image');
hold on;
for K=1:length(B)
boundary = B{K};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);
end
uiwait(msgbox('Note the green boundaries that have been drawn.'));
% Extract statistics
stats = regionprops
(labeledImage,'MajorAxisLength','MinorAxisLength');
uiwait(msgbox('Use the Variable Editor to examine the stats.'));

Subject: Lane Detection

From: Priti

Date: 2 Oct, 2009 12:54:02

Message: 5 of 6

Thank you. I've tried the following now. My issue now is to try to create a trapezoid by connecting the lane markings (trying to include 1 or 2 on each side) to find the bottom inner pixel location of the lane markings on either side. I'm using the following code so far:

% script to find and mark lanes

clear all
close all

%-- 9/30/09 5:35 PM --%
street1 = imread('street1.jpg');
street1 = imread('Camera_Stills\goodConditions_centerLane1.jpg');

imagesc(street1); shg
scaled=street1*1.2;
image(scaled);
level = 220;
binary = scaled>level;
imagesc(binary);
binary = bwareaopen(binary,100);
imagesc(binary)
%hold on

ttt=rgb2gray(double(binary));
[B,L] = bwboundaries(ttt,'noholes');

%imshow(binary)
figure,imshow(ttt)
hold on

stats = regionprops(L,'MajorAxisLength','MinorAxisLength', 'Orientation');

for K=1:length(B)
boundary = B{K};
h(K)=plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);
end

lanes=findlanes(B,h,stats);

% help findlanes
% figure,imshow(ttt)
% >> hold on
% for K=1:length(B),boundary = B{K};h(K)=plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);K,pause,end
% imshow(ttt),hold on
% for K=1:length(B),boundary = B{K};h(K)=plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);K,pause,end
 
function lanes=findlanes(B,h,stats)
% Find the regions that look like lanes
 
l=0;
for k = 1:length(B)
    metric = stats(k).MajorAxisLength/stats(k).MinorAxisLength;
    testlane(k);
end
    function testlane(k)
% if metric > 5 & all(B{k}(:,2)>100)
        if metric > 5 & all(B{k}(:,1)>150) & stats(k).MinorAxisLength<20 & abs(stats(k).Orientation)>30 ...
                & abs(stats(k).Orientation)<90 %& all(B{k}(:,2)<350)
            l=l+1;
            lanes(l,:)=B(k);
        else
            delete(h(k))
        end
    end
end

Subject: Lane Detection

From: Priti

Date: 8 Oct, 2009 16:55:19

Message: 6 of 6

So I have an idea of what to do. I was thinking of using
lanes=findlanes(B,h,stats)
which is an array of coordinates of points in the lane, and finding the extreme end points of the inner side of the lane markings and making a line that way. Would anyone be able to guide how to detect these end points?

Thank you!
Priti

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us