Create Custom Preprocessing Algorithm with Lidar Viewer - MATLAB & Simulink (original) (raw)

Main Content

This example shows how to create and import a custom preprocessing algorithm in the Lidar Viewer app.

The Lidar Viewer app is a tool to visualize, analyze, and preprocess lidar data. You can use this app to process your lidar data for processes such as labeling, segmentation, and calibration. You can either use the built-in preprocessing algorithms or create a custom algorithm.

In this example, you:

Load Point Cloud Data into Lidar Viewer

In this example, you first read point cloud data into the MATLABĀ® workspace using the pcread function.

% Read point cloud data ptCloud = pcread("HDL64LidarData.pcd");

To open the Lidar Viewer app, enter this command in the MATLAB Command Window.

Alternatively, you can select the app from the MATLAB Toolstrip, on the Apps tab. In theApps gallery, under Image Processing and Computer Vision, select Lidar Viewer.

On the Lidar Viewer app toolstrip, select > . In the Import From Workspace dialog box, selectptCloud and click OK.

Import From Workspace dialog box

The app loads the point cloud data ptCloud from the workspace and displays it in the Point Cloud Display pane.

Visualization of imported point cloud data in Lidar Viewer app

Create Custom Preprocessing Algorithm

On the app toolstrip, select the Edit tab. Then, follow these steps to create a custom algorithm using a MATLAB function and import it into the app.

  1. Click Create Algorithm. The app opens a new MATLAB function in the MATLAB editor. The default name of the function ismyAlgorithm.
  2. The myAlgorithm function contains sample code for editing the input point cloud. Replace the function with this code, which crops the point cloud by discarding points outside a spherical region with the specified radius.
    function ptCloudOut = radialCrop(ptCloudIn)
    % radialCrop Crop point cloud radially
    % ptCloudOut = radialCrop(ptCloudIn) radially crops the input point cloud
    % ptCloudIn and returns the output point cloud ptCloudOut.
    % Specify a query point and a radius to crop the point cloud radially
    % around the query point.
    point = [0 0 0];
    radius = 25;
    % Find indices of neighbors within the radius of the query point
    croppedLocations = findNeighborsInRadius(ptCloudIn,point,radius);
    % Crop the point cloud
    ptCloudOut = select(ptCloudIn,croppedLocations);
    end
  3. Save the function in your desired folder asradialCrop.m.

Import and Use Custom Preprocessing Algorithm

  1. To import the algorithm into the app, on the Edit tab of the app toolstrip, click Import Algorithm. Then, browse to the location of radialCrop.m, select the file, and click Open.
  2. After you import the algorithm, the app adds it to the gallery of algorithms in the Algorithm section.
    Algorithm gallery containing the custom algorithm
  3. To apply the custom algorithm to the input point cloud, select theradialCrop algorithm from theAlgorithm section.
    Note
    If the input point cloud contains multiple frames, the app opens the Confirm dialog. Select Yes to confirm that you want to apply the custom algorithm to all frames. Otherwise select,No.

This image shows the resulting point cloud after applying theradialCrop algorithm to the imported point cloud data.

Radially cropped point cloud

Export Point Cloud Data from Lidar Viewer

You can export point clouds as PCD, PLY, LAS, or LAZ files. After processing the point cloud, on the app toolstrip, in the Viewer tab, selectExport Point Cloud. In the Export Point Cloud dialog box, select the preprocessed point cloud. Then, specify Provide path to the destination folder as a destination file path, or clickBrowse and navigate to your destination folder. Select the desired Export format, and click OK to export the point cloud to the specified destination.

See Also

Apps

Topics