Main Content


Insert lane boundary into image



rgb = insertLaneBoundary(I,boundaries,sensor,xVehicle) inserts lane boundary markings into a truecolor image. The lanes are overlaid on the input road image, I. This image comes from the sensor specified in the sensor object. xVehicle specifies the x-coordinates at which to draw the lane markers. The y-coordinates are calculated based on the parameters of the boundary models in boundaries.


rgb = insertLaneBoundary(___,Name,Value) inserts lane boundary markings with additional options specified by one or more Name,Value pair arguments, using the previous input arguments.


collapse all

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);

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), ...

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 imageToVehicle function.

[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 parabolicLaneBoundary objects.

boundaries = findParabolicLaneBoundaries(xyBoundaryPoints,approxBoundaryWidth);

Use 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;

sensor = bevSensor.birdsEyeConfig.Sensor;
lanesI = insertLaneBoundary(I,boundaries(1),sensor,XPoints);
lanesI = insertLaneBoundary(lanesI,boundaries(2),sensor,XPoints,'Color','green');

View the lanes in the bird's-eye-view image.

BEconfig = bevSensor.birdsEyeConfig;
lanesBEI = insertLaneBoundary(birdsEyeImage,boundaries(1),BEconfig,XPoints);
lanesBEI = insertLaneBoundary(lanesBEI,boundaries(2),BEconfig,XPoints,'Color','green');

Input Arguments

collapse all

Input road image, specified as a truecolor or grayscale image.

Data Types: single | double | int8 | int16 | uint8 | uint16

Lane boundary models, specified as an array of parabolicLaneBoundary objects or cubicLaneBoundary objects. Lane boundary models contain the following properties:

  • 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 ObjectParameters

    [A B C], corresponding to coefficients of a second-degree polynomial equation of the form y = Ax2 + Bx + C

    cubicLaneBoundary[A B C D], corresponding to coefficients of a third-degree polynomial equation of the form y = Ax3 + Bx2 + Cx + D
  • BoundaryType — A LaneBoundaryType enumeration of supported lane boundaries:

    • Unmarked

    • Solid

    • Dashed

    • BottsDots

    • DoubleSolid

    Specify a lane boundary type as LaneBoundaryType.BoundaryType. 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 property.

  • XExtent — A two-element vector describing the minimum and maximum x-axis locations for the boundary points.

Sensor that collects images, specified as either a birdsEyeView or monoCamera object.

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.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is 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.

Example: 'Color',[0 1 0]

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 'blue', 'green', 'red', 'cyan', 'magenta', 'yellow', 'black', and 'white'.

Example: 'red'

Example: [1,0,0]

Line width for boundary lanes, specified as a positive integer in pixels.

Output Arguments

collapse all

Image with boundary lanes overlaid, returned as an RGB truecolor image. The output image class matches the input image, I.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2017a