Find boundaries using parabolic model
uses the random sample consensus (RANSAC) algorithm to find parabolic lane boundary
models that fit a set of boundary points and an approximate width. Each model in the
returned array of
boundaries = findParabolicLaneBoundaries(
[A B C] coefficients of its second-degree polynomial
equation and the strength of the boundary estimate.
[___] = findParabolicLaneBoundaries(___,
uses options specified by one or more
Name,Value pair arguments,
with any of the preceding syntaxes.
Find lanes in an image by using parabolic lane boundary models. Overlay the identified lanes on the original image and on a bird's-eye-view transformation of the image.
Load an image of a road with lanes. The image was obtained from a camera sensor mounted on the front of a vehicle.
I = imread('road.png');
Transform the image into a bird's-eye-view image by using a preconfigured sensor object. This object models the sensor that captured the original image.
bevSensor = load('birdsEyeConfig'); birdsEyeImage = transformImage(bevSensor.birdsEyeConfig,I); imshow(birdsEyeImage)
Set the approximate lane marker width in world units (meters).
approxBoundaryWidth = 0.25;
Detect lane features and display them as a black-and-white image.
birdsEyeBW = segmentLaneMarkerRidge(rgb2gray(birdsEyeImage), ... bevSensor.birdsEyeConfig,approxBoundaryWidth); imshow(birdsEyeBW)
Obtain lane candidate points in world coordinates.
[imageX,imageY] = find(birdsEyeBW); xyBoundaryPoints = imageToVehicle(bevSensor.birdsEyeConfig,[imageY,imageX]);
Find lane boundaries in the image by using the
findParabolicLaneBoundaries function. By default, the function returns a maximum of two lane boundaries. The boundaries are stored in an array of
boundaries = findParabolicLaneBoundaries(xyBoundaryPoints,approxBoundaryWidth);
insertLaneBoundary to overlay the lanes on the original image. The
XPoints vector represents the lane points, in meters, that are within range of the ego vehicle's sensor. Specify the lanes in different colors. By default, lanes are yellow.
XPoints = 3:30; figure sensor = bevSensor.birdsEyeConfig.Sensor; lanesI = insertLaneBoundary(I,boundaries(1),sensor,XPoints); lanesI = insertLaneBoundary(lanesI,boundaries(2),sensor,XPoints,'Color','green'); imshow(lanesI)
View the lanes in the bird's-eye-view image.
figure BEconfig = bevSensor.birdsEyeConfig; lanesBEI = insertLaneBoundary(birdsEyeImage,boundaries(1),BEconfig,XPoints); lanesBEI = insertLaneBoundary(lanesBEI,boundaries(2),BEconfig,XPoints,'Color','green'); imshow(lanesBEI)
xyBoundaryPoints— Candidate boundary points
approxBoundaryWidth— Approximate boundary width
Approximate boundary width, specified as a real scalar in world units. The width is a horizontal y-axis measurement.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'MaxNumBoundaries'— Maximum number of lane boundaries
2(default) | positive integer
Maximum number of lane boundaries that the function attempts to find,
specified as the comma-separated pair consisting of
'MaxNumBoundaries' and a positive integer.
'ValidateBoundaryFcn'— Function to validate boundary model
Function to validate the boundary model, specified as the
comma-separated pair consisting of
'ValidateBoundaryFcn' and a function handle. The
specified function returns logical
1 (true) if the
boundary model is accepted and logical
otherwise. Use this function to reject invalid boundaries. The function
must be of the
isValid = validateBoundaryFcn(parameters)
parameters is a vector corresponding to the three
The default validation function always returns
'MaxSamplingAttempts'— Maximum number of sampling attempts
100(default) | positive integer
Maximum number of attempts to find a sample of points that yields a
valid parabolic boundary, specified as the comma-separated pair
'MaxSamplingAttempts' and a function
findParabolicLaneBoundaries uses the
function to sample from the set of boundary points and fit a parabolic
boundaries— Lane boundary models
Lane boundary models, returned as an array of
objects. Lane boundary objects contain the following properties:
Parameters — A three-element vector,
[A B C], that corresponds to the three
coefficients of a second-degree polynomial equation in general
form: y =
+ Bx +
BoundaryType — A
LaneBoundaryType of supported lane
boundaries. The supported lane boundary types are:
Specify a lane boundary type as
Strength — A ratio of the number of unique
x-axis locations on the boundary to the
total number of points along the line, based on the
XExtent — A two-element vector describing
the minimum and maximum x-axis locations for
the boundary points.
boundaryPoints— Inlier boundary points
Inlier boundary points, returned as a cell array of
y] values. Each element of the cell array corresponds to the
same element in the array of
To fit a single boundary model to a double lane marker, set the
approxBoundaryWidth argument to be large enough to
include the width spanning both lane markers.
This function uses
fitPolynomialRANSAC to find
parabolic models. Because this algorithm uses random sampling, the output can
vary between runs.
maxDistance parameter of
fitPolynomialRANSAC is set to
half the width specified in the
argument. Points are considered inliers if they are within the boundary width.
The function obtains the final boundary model using a least-squares fit on the