matlab 点云采样相关操作-源码复制粘贴即可

1.随机采样=一个百分点的随机抽样

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot; % points are colored by z coordinate
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Select randomly 5 percent of all points
pc.select('RandomSampling', 5);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''RandomSampling''', 'Color', 'w'); view(0,0);

 

 2.间隔采样=根据X中点的顺序选择每n个点

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Select each 50-th point
pc.select('IntervalSampling', 50);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''IntervalSampling''', 'Color', 'w'); view(0,0);

3. 均匀采样=对空间中的点进行均匀采样

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Select points using a voxelSize of 3
pc.select('UniformSampling', 3);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''UniformSampling''', 'Color', 'w'); view(0,0);

 4.最大杠杆抽样=根据他们的“杠杆”选择点

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% First, let's select a subset of points with the UniformSampling strategy
pc.select('UniformSampling', 2);

% Calculate the normals of the selected points with a searchRadius of 1
pc.normals(1);

% Now, select 25 percent of the points with the MaxLeverageSampling strategy
pc.select('MaxLeverageSampling', 25);

% Plot only selected points
close; pc.plot('MarkerSize', 5);
title('After selection strategy ''MaxLeverageSampling''', 'Color', 'w'); view(0,0);

 

 5.正态抽样=基于法向量的点选择

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% First, let's select a subset of points with the UniformSampling strategy
pc.select('UniformSampling', 2);

% Calculate the normals of the selected points with a search radius of 1
pc.normals(1);

% Now, select 25 percent of the points with the NormalSampling strategy
pc.select('NormalSampling', 25);

% Plot only selected points
close; pc.plot('MarkerSize', 5);
title('After selection strategy ''NormalSampling''', 'Color', 'w'); view(0,0);

 

6.属性=基于属性的点选择

The attribute has to be a field of the structure obj.A, e.g. obj.A.roughness.

clc; clear; close all; % clear everything

% Import point cloud WITH attributes (nx, ny, nz are the components of the normal vector)
pc = pointCloud('Lion.xyz', 'Attributes', {'nx' 'ny' 'nz' 'roughness'});

Note: the imported attributes are saved now as fields in the structure pc.A, e.g. the roughness in saved in pc.A.roughness.

% Plot all points
pc.plot('Color', 'A.roughness', 'CAxisLim', [0 1]); % colored by roughness; range of color bar from 0 to 1
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Select points with roughness in the specified range; in doing so, only the smooth parts of the point cloud are selected
roughnessRange = [0.01 0.3];
pc.select('Attribute', 'roughness', roughnessRange);

% Plot only selected points
close; pc.plot('Color', 'A.roughness', 'CAxisLim', [0 1]);
title('After selection strategy ''Attribute''', 'Color', 'w'); view(0,0);

 7.限制=选择窗口内点的选择

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Selection of the lions head
limitsMinMax = [-Inf -10
                 -30  20
                 -10 Inf];

pc.select('Limits', limitsMinMax);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''Limits''', 'Color', 'w'); view(0,0);

 8.InPolygon =选择二维多边形区域内的点

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Selection of the lions tail within the specified polygon
polygon = [45  4
           45 -7
           56 -7
           71 -2
           71  4
           63  6];

pc.select('InPolygon', polygon);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''InPolygon''', 'Color', 'w'); view(0,0);

 9.InVoxelHull =选择指定体素hull内部的点

clc; clear; close all; % clear everything

% Import the two point clouds
pcScan1 = pointCloud('LionScan1.xyz');
pcScan2 = pointCloud('LionScan2.xyz');

% Plot them in different colors
pcScan1.plot('Color', 'm'); % magenta
pcScan2.plot('Color', 'y'); % yellow
title('Both point clouds', 'Color', 'w'); view(0,0); snapnow;

% Select points of second point cloud which are inside of the voxel hull of the first point cloud
voxelSize = 2;
pcScan1.getVoxelHull(voxelSize); % get voxel hull of first point cloud

pcScan2.select('InVoxelHull', pcScan1.voxelHull, ...
                              pcScan1.voxelHullVoxelSize);

% Plot only selected points
close; pcScan2.plot('Color', 'y');
title('Only points of yellow pc which are overlapping with magenta pc', 'Color', 'w'); view(0,0);

10 RangeSearch =选择另一个点云范围内的点 

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% First select a subset of points with uniform sampling, then search all points within the range of 1 from these points
pc.select('UniformSampling', 5);

points = pc.X(pc.act,:); % save selected points to matrix

pc.select('All'); % reselect all points

searchRadius = 1;
pc.select('RangeSearch', points, searchRadius);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''RangeSearch''', 'Color', 'w'); view(0,0);

11. KnnSearch =为另一个点云的每个点选择K个最近邻

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% First select a subset of points with uniform sampling, then search the 500 nearest neighbors of these points
pc.select('UniformSampling', 10);

points = pc.X(pc.act,:); % save selected points to matrix

pc.select('All'); % reselect all points

pc.select('KnnSearch', points, 'K', 500);

% Plot only selected points
close; pc.plot;
title('After selection strategy ''KnnSearch''', 'Color', 'w'); view(0,0);

 

12.剖面=垂直剖面内点的选择

clc; clear; close all; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz');

% Plot all points
pc.plot;
title('All Points', 'Color', 'w'); view(0,0); snapnow;

% Select a crossection
lineStart = [ 100 0];
lineEnd   = [-100 0];
lineWidth = 2;
az = pc.select('Profile', lineStart, lineEnd, lineWidth); % az contains the azimuth of cross section (to use with function view, see below)

% Plot only selected points
close; pc.plot;
title('After selection strategy ''Profile''', 'Color', 'w'); view(az,0);

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值