LiDAR 点群データの読み取り、処理、書き込み
この例では、点群をワークスペースに読み取り、目的の点集合を選択して、選択された点を点群ファイルの形式に書き込む方法を示します。
手順 1: 点群の読み取りと表示
関数 lasFileReader
を使用して、.las
ファイルからワークスペースにデータを読み取ります。出力 lasFileReader
オブジェクトに格納されたプロパティを表示します。
fileName = fullfile(toolboxdir("lidar"),"lidardata","las","aerialLidarData.laz"); lasReader = lasFileReader(fileName)
lasReader = lasFileReader with properties: FileName: '/mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2511836/build/matlab/toolbox/lidar/lidardata/las/aerialLidarData.laz' Count: 1018047 LasVersion: '1.0' XLimits: [4.2975e+05 4.3015e+05] YLimits: [3.6798e+06 3.6801e+06] ZLimits: [72.7900 125.8200] GPSTimeLimits: [3.3355e+05 sec 3.3443e+05 sec] NumReturns: 4 NumClasses: 10 SystemIdentifier: 'LAStools (c) by rapidlasso GmbH' GeneratingSoftware: 'TerraScan + OT' FileCreationDate: 28-Apr-2020 FileSourceID: 0 ProjectID: '0-0-0-00000000' PointDataFormat: 1 ClassificationInfo: [6x3 table] LaserReturnInfo: [4x2 table] VariableLengthRecords: [3x3 table]
.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: FileName: '/tmp/Bdoc24a_2511836_2592632/tp051b160b/lidar-ex04737654/aerialvegetation.las' Count: 116598 LasVersion: '1.2' XLimits: [4.2995e+05 4.3015e+05] YLimits: [3.6798e+06 3.6801e+06] ZLimits: [84.9500 123.1100] GPSTimeLimits: [0 sec 0 sec] NumReturns: 1 NumClasses: 1 SystemIdentifier: 'MATLAB' GeneratingSoftware: 'LasFileWriter v1.0' FileCreationDate: 24-Jan-2024 FileSourceID: 0 ProjectID: '0-0-0-00000000' PointDataFormat: 3 ClassificationInfo: [1x3 table] LaserReturnInfo: [1x2 table] VariableLengthRecords: [1x3 table]
参考
lasFileReader
| pcshow
| readPointCloud
| findPointsInROI
| pointCloud
| select