Detect lanes in a grayscale intensity image
returns a binary image that represents lane features. The function segments the
input grayscale intensity image,
birdsEyeBW = segmentLaneMarkerRidge(
birdsEyeImage, using a
lane ridge detector.
birdsEyeConfig transforms point
locations from vehicle coordinates to image coordinates. The
approxMarkerWidth argument is in world units, and
specifies the approximate width of the lane-like features that are
Detect Lanes in Road Image
Load a bird's-eye-view configuration object.
Load the image captured from the sensor that is defined in the bird's-eye-view configuration object.
I = imread('road.png'); figure imshow(I) title('Original Image')
Create a bird's-eye-view image.
birdsEyeImage = transformImage(birdsEyeConfig,I); imshow(birdsEyeImage)
Convert bird's-eye-view image to grayscale.
birdsEyeImage = im2gray(birdsEyeImage);
Set the approximate lane marker width to 25 cm, which is in world units.
approxMarkerWidth = 0.25;
Detect lane features.
birdsEyeBW = segmentLaneMarkerRidge(birdsEyeImage,birdsEyeConfig,approxMarkerWidth); imshow(birdsEyeBW)
birdsEyeImage — Bird’s-eye-view image
Bird’s-eye-view image, specified as a nonsparse matrix.
birdsEyeConfig — Object to transform point locations
Object to transform point locations from vehicle to image coordinates,
specified as a
approxMarkerWidth — Approximate width of lane-like features
real scalar in world units
Approximate width of lane-like features for the function to detect in the bird’s-eye-view image, specified as a real scalar in world units, such as meters.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
ROI — Region of interest
 (default) | world units
Region of interest in world units, specified as the comma-separated
pair consisting of
'ROI' and a 1-by-4 vector in the
The function searches for lane-like features only within this region of
interest. If you do not specify
ROI, the function
searches the entire image.
Sensitivity — Sensitivity factor
0.25 (default) | real scalar in the range [0, 1]
Sensitivity factor, specified as the comma-separated pair consisting
'Sensitivity' and a real scalar in the range [0,
1]. You can increase this value to detect more lane-like features.
However, the higher sensitivity can increase the risk of false
birdsEyeBW — Bird’s-eye-view image
Bird’s-eye-view image, returned as a binary image that represents lane features.
segmentLaneMarkerRidge selects lanes by searching for pixels that
are lane-like. Lane-like pixels are groups of pixels with
high-intensity contrast compared to neighboring pixels on either side. The function
chooses the filter used to threshold the intensity contrast based on the
approxMarkerWidth value. The filter has high responses for
pixels with intensity values higher than those of the left and right neighboring pixels
that have a similar intensity at a distance of
The function retains only certain values from the filtered image based on the
 Nieto, M., J. A. Laborda, and L. Salgado. “Road Environment Modeling Using Robust Perspective Analysis and Recursive Bayesian Segmentation.” Machine Vision and Applications. Volume 22, Issue 6, 2011, pp. 927–945.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Introduced in R2017a