读取、处理和写入激光雷达点云数据
R2026b此示例说明如何将点云读取到工作区,选择所需的点集,然后以点云文件格式写入所选的点。
步骤 1:读取并显示点云
使用 lasFileReader 函数将 .las 文件中的数据读取到工作区。显示输出 lasFileReader 对象中存储的属性。
fileName = fullfile(toolboxdir("pointcloud"),"pcdata","las","aerialLidarData.laz"); lasReader = lasFileReader(fileName)
lasReader =
lasFileReader with properties:
Count: 1018047
XLimits: [4.2975e+05 4.3015e+05]
YLimits: [3.6798e+06 3.6801e+06]
ZLimits: [72.7900 125.8200]
Attributes: ["Classification" "LaserReturn" "NumReturns" "ScanDirectionFlag" "EdgeOfFlightLineFlag" "ScanAngle" "UserData" "PointSourceID" "GPSTimeStamp"]
ClassificationInfo: "To get the value, enter lasReader.ClassificationInfo at the Command Window. Learn more"
LaserReturnInfo: [4×2 table]
VariableLengthRecords: [3×3 table]
Show all properties
从 .las 文件中读取点云。
ptCloud = readPointCloud(lasReader);
显示点云。
fig = figure(Position=[0 0 800 400]); hPanel = uipanel(fig); hPlot = axes(hPanel); pcshow(ptCloud.Location,Parent=hPlot)

步骤 2:选择所需的点集
您可以通过指定目标类的分类值以及感兴趣区域 (ROI) 内的点的索引,在输入点云中选择所需的一组点。
通过指定分类值来选择点
要通过指定分类值来选择点,请使用
lasFileReader对象的ClassificationInfo属性,读取输入点云中有关目标类的信息。
disp(lasReader.ClassificationInfo)
Classification Value Class Name Number of Points by Class
____________________ ___________________ _________________________
1 "Unclassified" 114842
2 "Ground" 646632
4 "Medium Vegetation" 210101
6 "Building" 45699
8 "Reserved(8)" 751
9 "Water" 22
使用
readpointCloud函数指定要从输入点云中读取的目标类对应的分类值。要读取对应于中等植被区域的点,请将Classification名称-值参量的值设置为 4。
ptCloudB = readPointCloud(lasReader,Classification=4);
显示点云。
fig1 = figure(Position=[0 0 800 400]); hPanel1 = uipanel(fig1); hPlot1 = axes(hPanel1); pcshow(ptCloudB.Location,Parent=hPlot1)

通过指定索引来选择点
在输入点云的 x、y 和 z 坐标范围内定义长方体 ROI。
roi = [lasReader.XLimits(1)+200, lasReader.XLimits(2), ...
lasReader.YLimits(1), lasReader.YLimits(2), lasReader.ZLimits(1), lasReader.ZLimits(2)];查找位于长方体 ROI 内的点的索引。
indices = findPointsInROI(ptCloudB,roi);
选择位于长方体 ROI 内的点,并将其存储为点云对象。
ptCloudC = select(ptCloudB,indices);
显示点云。
fig2 = figure(Position=[0 0 800 400]); hPanel2 = uipanel(fig2); hPlot2 = axes(hPanel2); pcshow(ptCloudC.Location,Parent=hPlot2)

步骤 3:以 .las 文件格式写入所选的点
指定 .las 文件的名称并创建一个 lasFileWriter 对象。
newfileName = "aerialvegetation.las";
lasWriter = lasFileWriter(newfileName);使用 writePointCloud 函数将所选的点写入到 .las 文件。该函数在当前工作目录中创建新文件。
writePointCloud(lasWriter,ptCloudC);
步骤 4:检查新写入文件的属性
newlasReader = lasFileReader(newfileName)
newlasReader =
lasFileReader with properties:
Count: 116598
XLimits: [4.2995e+05 4.3015e+05]
YLimits: [3.6798e+06 3.6801e+06]
ZLimits: [84.9500 123.1100]
Attributes: ["Classification" "LaserReturn" "NumReturns" "ScanDirectionFlag" "EdgeOfFlightLineFlag" "ScanAngle" "UserData" "PointSourceID" "GPSTimeStamp" "ScannerChannel"]
ClassificationInfo: "To get the value, enter newlasReader.ClassificationInfo at the Command Window. Learn more"
LaserReturnInfo: [1×2 table]
VariableLengthRecords: [1×3 table]
Show all properties
另请参阅
lasFileReader | pcshow | readPointCloud | findPointsInROI | pointCloud | select