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 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 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)
I— Input road image
Input road image, specified as a truecolor or grayscale image.
boundaries— Lane boundary models
parabolicLaneBoundaryobjects | 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|
BoundaryType — A
LaneBoundaryType enumeration of supported lane boundaries:
Specify a lane boundary type as
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.
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
'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.