Insert lane boundary into image
inserts lane boundary markings into a truecolor image. The lanes are overlaid on the input
rgb = insertLaneBoundary(
I. This image comes from the sensor specified in the
xVehicle specifies the
x-coordinates at which to draw the lane markers. The
y-coordinates are calculated based on the parameters of the boundary
Find Parabolic Lane Boundaries in Bird's-Eye-View Image
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(im2gray(birdsEyeImage), ... bevSensor.birdsEyeConfig,approxBoundaryWidth); imshow(birdsEyeBW)
Obtain the image coordinates corresponding to the lane candidate positions. The
find function returns pixel indices that correspond to the candidate lane positions. By convention, the order of the image coordinates is always reversed relative to the pixel indices. For more information about image coordinates, see Coordinate Systems.
Obtain the corresponding lane boundary points in vehicle coordinates by using the
[imageY,imageX] = find(birdsEyeBW); xyBoundaryPoints = imageToVehicle(bevSensor.birdsEyeConfig,[imageX,imageY]);
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)
I — Input road image
truecolor image | grayscale image
Input road image, specified as a truecolor or grayscale image.
boundaries — Lane boundary models
parabolicLaneBoundary objects | array of
Parameters— A vector corresponding to the coefficients of the boundary model. The size of the vector depends on the degree of polynomial for the model.
Lane Boundary Object Parameters
[A B C], corresponding to coefficients of a second-degree polynomial equation of the form y = Ax2 + Bx + C
[A B C D], corresponding to coefficients of a third-degree polynomial equation of the form y = Ax3 + Bx2 + Cx + D
LaneBoundaryTypeenumeration of supported lane boundaries:
Specify a lane boundary type as
LaneBoundaryType.. For example:
Strength— The 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.
xVehicle — x-axis locations of boundary
x-axis locations at which to display the lane boundaries,
specified as a real-valued vector in vehicle coordinates. The spacing between points
controls the spacing between dashes and dots for the corresponding types of boundaries.
To show dashed boundaries clearly, specify at least four points in
xVehicle. If you specify fewer than four points, the function
draws a solid boundary.
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.
'Color',[0 1 0]
Color — Color of lane boundaries
'yellow' (default) | character vector | string scalar |
[R,G,B] vector of RGB values | cell array of character vectors | string array | m-by-3 matrix of RGB values
Color of lane boundaries, specified as a character vector, string scalar, or
[R,G,B] vector of RGB values. You can specify specific colors for
each boundary in
boundaries with a cell array of character
vectors, a string array, or an m-by-3 matrix of RGB values. The
colors correspond to the order of the boundary lanes.
RGB values must be in the range of the image data type.
Supported color values are
LineWidth — Line width for boundary lanes
3 (default) | positive integer
Line width for boundary lanes, specified as a positive integer in pixels.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Introduced in R2017a