insertLaneBoundary
Insert lane boundary into image
Syntax
Description
inserts lane boundary markings into a truecolor image. The lanes are overlaid on the input
road image, rgb
= insertLaneBoundary(I
,boundaries
,sensor
,xVehicle
)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
.
inserts lane boundary markings with additional options specified by one or more
rgb
= insertLaneBoundary(___,Name,Value
)Name,Value
pair arguments, using the previous input arguments.
Examples
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 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; 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)
Input Arguments
I
— Input road image
truecolor image | grayscale image
Input road image, specified as a truecolor or grayscale image.
Data Types: single
| double
| int8
| int16
| uint8
| uint16
boundaries
— Lane boundary models
array of parabolicLaneBoundary
objects | array of cubicLaneBoundary
objects
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 Object Parameters parabolicLaneBoundary
[A B C]
, corresponding to coefficients of a second-degree polynomial equation of the form y = Ax2 + Bx + CcubicLaneBoundary
[A B C D]
, corresponding to coefficients of a third-degree polynomial equation of the form y = Ax3 + Bx2 + Cx + DBoundaryType
— ALaneBoundaryType
enumeration of supported lane boundaries:Unmarked
Solid
Dashed
BottsDots
DoubleSolid
Specify a lane boundary type as
LaneBoundaryType.
. For example:BoundaryType
LaneBoundaryType.BottsDots
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 theXExtent
property.XExtent
— A two-element vector describing the minimum and maximum x-axis locations for the boundary points.
sensor
— Sensor that collects images
birdsEyeView
object | monoCamera
object
Sensor that collects images, specified as either a birdsEyeView
or monoCamera
object.
xVehicle
— x-axis locations of boundary
real-valued vector
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
— 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 'blue'
, 'green'
,
'red'
, 'cyan'
, 'magenta'
,
'yellow'
, 'black'
, and
'white'
.
Example: 'red'
Example: [1,0,0]
LineWidth
— Line width for boundary lanes
3
(default) | positive integer
Line width for boundary lanes, specified as a positive integer in pixels.
Output Arguments
rgb
— Image with boundary lanes
RGB truecolor image
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
See Also
parabolicLaneBoundary
| cubicLaneBoundary
| fitPolynomialRANSAC
| monoCamera
| birdsEyeView
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)