Main Content

laneBoundaryDetector

Detector for lane boundaries in images

Since R2023a

Description

The laneBoundaryDetector object detects lane boundaries in images by using a pretrained Cross Layer Refinement Network (CLRNet) lane detection model [1] or a pretrained recursive video lane detector (RVLD) model [2].

Note

This object requires an internet connection to download the pretrained lane detection models for its first use.

Creation

Description

detector = laneBoundaryDetector creates a default laneBoundaryDetector object detector to detect lane boundaries in images.

example

detector = laneBoundaryDetector(Model=modelName) creates a laneBoundaryDetector object detector using the specified lane detection model modelName.

example

Note

This object requires the Scenario Builder for Automated Driving Toolbox™ support package, Deep Learning Toolbox™, and the Deep Learning Toolbox Converter for ONNX™ Model Format support package. You can install the Scenario Builder for Automated Driving Toolbox and Deep Learning Toolbox Converter for ONNX Model Format support packages from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Input Arguments

expand all

Lane detection model, specified as "CLRNet" or "RVLD".

  • "CLRNet" — Uses the CLRNet model for lane detection. By default, the object uses the pretrained CLRNet model downloaded when you first create the object. For more information, see CLRNet.

    Note

    The CLRNet model requires the Deep Learning Toolbox Converter for ONNX Model Format support package.

  • "RVLD" — Uses the RVLD model for lane detection. If you specify modelName as "RVLD" and the RVLD model is not installed, the function opens an Optional Setup for Scenario Builder for Automated Driving Toolbox window, from which you can download and install the model. For more information on installation instructions, see Optional Set Up for Scenario Generation. For more information on the RVLD model, see RVLD. (since R2025a)

This argument sets the Model property.

Output Arguments

expand all

Lane boundary detector, returned as a laneBoundaryDetector object.

Properties

expand all

This property is read-only after object creation. To set this property, use the modelName input argument when creating the laneBoundaryDetector object.

Name of the lane detection model, represented as "CLRNet" or "RVLD".

This property is read-only.

Path on which the lane detection model is stored, represented as a string scalar or character vector.

Object Functions

detectDetect lane boundaries in images

Examples

collapse all

Detect lane boundary points in an RGB image by using the laneBoundaryDetector object.

Read an image into the workspace.

I = imread("highway.png");

Initialize the laneBoundaryDetector object with CLRNet model.

detector = laneBoundaryDetector;

Detect the boundary points of the lanes in the image by using the detect object function of the laneBoundaryDetector object.

lanes = detect(detector,I,ROI=120,ExecutionEnvironment="cpu");

Insert the detected lane boundary points into the image, as markers, by using the insertMarker function.

for i = 1:size(lanes{1},2)
    if ~isempty(lanes{1}{i})
        I = insertMarker(I,lanes{1}{1,i},"o",Size=3);
    end
end

Display the image, annotated with the detected lane boundary points.

imshow(I)

Since R2025a

Detect lane boundary points in RGB images by using the laneBoundaryDetector object.

Download a ZIP file containing a subset of sensor data from the PandaSet data set, and then unzip the file. This data set contains camera images and camera sensor parameters collected using a forward-facing camera mounted on an ego vehicle.

dataFolder = pwd;
dataFilename = "PandasetSensorData_23a.zip";
url = "https://ssd.mathworks.com/supportfiles/driving/data/" + dataFilename;
filePath = fullfile(dataFolder,dataFilename);
if ~isfile(filePath)
    websave(filePath,url)
end
unzip(filePath,dataFolder)
dataset = fullfile(dataFolder,"PandasetSensorData");
data = fullfile(dataset,"Camera");

Create an image datastore from the loaded images.

imds = imageDatastore(data)
imds = 
  ImageDatastore with properties:

                       Files: {
                              ' .../bsahoo/CustomerFiles/RVLD/Example/PandasetSensorData/Camera/0001.jpg';
                              ' .../bsahoo/CustomerFiles/RVLD/Example/PandasetSensorData/Camera/0002.jpg';
                              ' .../bsahoo/CustomerFiles/RVLD/Example/PandasetSensorData/Camera/0003.jpg'
                               ... and 397 more
                              }
                     Folders: {
                              ' .../sandbox/bsahoo/CustomerFiles/RVLD/Example/PandasetSensorData/Camera'
                              }
    AlternateFileSystemRoots: {}
                    ReadSize: 1
                      Labels: {}
      SupportedOutputFormats: ["png"    "jpg"    "jpeg"    "tif"    "tiff"]
         DefaultOutputFormat: "png"
                     ReadFcn: @readDatastoreImage

Create a subset datastore, subimds, that contains the first 15 image files of imds.

subimds = subset(imds,(1:15));

Initialize a laneBoundaryDetector object with the RVLD model.

detector = laneBoundaryDetector(Model="RVLD");

Detect the boundary points of the lanes in the sequence of images by using the detect object function of the laneBoundaryDetector object.

lanes = detect(detector,subimds,ROI=500,ExecutionEnvironment="cpu");

Insert the detected lane boundary points into the sequences of images, as markers, by using the insertShape function.

for i = 1:numel(subimds.Files)
    img = readimage(subimds,i);
    for j = 1:size(lanes{i},2)
        if ~isempty(lanes{i}{j})          
            img = insertShape(img,"line",lanes{i}{1,j},LineWidth=8,ShapeColor="yellow");
        end
    end
    imshow(img) 
end

More About

expand all

References

[1] Zheng, Tu, Yifei Huang, Yang Liu, Wenjian Tang, Zheng Yang, Deng Cai, and Xiaofei He. “CLRNet: Cross Layer Refinement Network for Lane Detection.” In 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 888–97. New Orleans, LA, USA: IEEE, 2022. https://doi.org/10.1109/CVPR52688.2022.00097.

[2] Jin, Dongkwon, Dahyun Kim, and Chang-Su Kim. “Recursive Video Lane Detection.” In 2023 IEEE/CVF International Conference on Computer Vision (ICCV), 8439–48. Paris, France: IEEE, 2023. https://doi.org/10.1109/ICCV51070.2023.00778.

Version History

Introduced in R2023a

expand all