Main Content

라이다 포인트 클라우드 데이터 읽기, 처리하기, 쓰기

이 예제에서는 포인트 클라우드를 작업 공간으로 읽어오고 원하는 일련의 점들을 선택한 다음 선택한 점들을 포인트 클라우드 파일 형식에 쓰는 방법을 보여줍니다.

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)

Figure contains an axes object and an object of type uipanel. The axes object contains an object of type scatter.

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)

Figure contains an axes object and an object of type uipanel. The axes object contains an object of type scatter.

인덱스를 지정하여 점 선택하기

입력 포인트 클라우드의 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 범위 내에 있는 점들을 선택하고 point cloud 객체로 저장합니다.

ptCloudC = select(ptCloudB,indices);

포인트 클라우드를 표시합니다.

fig2 = figure(Position=[0 0 800 400]);
hPanel2 = uipanel(fig2);
hPlot2 = axes(hPanel2);
pcshow(ptCloudC.Location,Parent=hPlot2)

Figure contains an axes object and an object of type uipanel. The axes object contains an object of type scatter.

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]

참고 항목

| | | | |