matlab点云的可视化-源码复制粘贴即可(一)

 一、导入并可视化一个无属性的点云

clc; clear; close; % clear everything

% Import a point cloud from a plain text file (run type('Lion.xyz') to see the contents of the file)
pc = pointCloud('Lion.xyz');

% Generate a z-colored view of the point cloud
pc.plot;

% Set three-dimensional view and add title
view(3); title('Z-colored plot of point cloud', 'Color', 'w');

 

二、导入并加载一个有属性的点云

clc; clear; close; % clear everything

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

% Plot point cloud colored according to imported attribute 'roughness'
pc.plot('Color', 'A.roughness', ... % attribute to plot
        'MarkerSize', 5); % size of points

% Set three-dimensional view and add title
view(3); title('Point cloud colored by roughness point attribute', 'Color', 'w');

 三、从矩阵中导入点云

 

clc; clear; close; % clear everything

% Generate points on a unit sphere
[x, y, z] = sphere(100);
x = x(:); y = y(:); z = z(:);

% Import points and define a label for the point cloud
pc = pointCloud([x y z], 'Label', 'sphere');

% Plot point cloud
pc.plot('MarkerSize', 5);

% Set three-dimensional view and add title
view(3); title('Sphere', 'Color', 'w');

 四、点云的rgb色图

clc; clear; close; % clear everything

% Import point cloud with attributes red, green and blue
pc = pointCloud('Dino.xyz', 'Attributes', {'r' 'g' 'b'});

% Plot point cloud
pc.plot('Color', 'A.rgb', ... % rgb-colored plot
        'MarkerSize', 5); % size of points

% Set three-dimensional view and add title
view(110,0); title('RGB-colored point cloud', 'Color', 'w');

 

五、导入两个点云,并以不同的颜色可视化它们

clc; clear; close; % clear everything

% Import point clouds
scan1 = pointCloud('LionScan1.xyz');
scan2 = pointCloud('LionScan2.xyz');

% Plot
scan1.plot('Color', 'y'); % yellow
scan2.plot('Color', 'm'); % magenta

% Set three-dimensional view and add title
view(3); title('Scan1 (=yellow) and scan2 (=magenta)', 'Color', 'w');

 六、选择点的子集(即过滤/稀释点云)并将它们导出到文本文件

clc; clear; close; % clear everything

% Import point cloud
pc = pointCloud('Lion.xyz', 'Attributes', {'nx' 'ny' 'nz' 'roughness'});

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

% Export selected points to a plain text file with attributes
pc.export('LionSubset.xyz', 'Attributes', {'nx' 'ny' 'nz' 'roughness'});

% Plot
pc.plot('MarkerSize', 5);

% Set title
title('Z-colored plot of a subset of points', 'Color', 'w');

 

注意:属性pc。Act是一个n × 1的逻辑向量,定义每个点是活动(true)还是不活动(false)。
大多数方法只适用于活动点。

七、计算点云的法线并可视化它们

clc; clear; close; % clear everything

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

% Select a random subset of points
pc.select('RandomSampling', 1); % select randomly 1 percent of points

% Calculate normals (normals are only calculated for the selected points)
pc.normals(2); % search radius is 2

% Plot point cloud and normals
pc.plot('MarkerSize', 5);
pc.plotNormals('Scale', 10, 'Color', 'y'); % lenght of normals is 10

% Set three-dimensional view and add title
view(3); title('Normal vectors', 'Color', 'w');

 八、变换点云 Transform a point cloud

clc; clear; close; % clear everything

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

% Plot original point cloud
pc.plot('Color', 'y');

% Transformation with a rotation angle of 100 gradians about the z axis
pc.transform(1, opk2R(0, 0, 100), zeros(3,1)); % opk2R generates a rotation matrix from 3 rotation angles (about the x, y and z axis / units = gradian!)

% Plot transformed point cloud
pc.plot('Color', 'm'); title('Point cloud transformation', 'Color', 'w');

 

九、保存和加载点云

clc; clear; close; % clear everything

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

% Save to mat file
pc.save('Lion.mat');

% Clear point cloud
clear pc;

% Load point cloud from mat file
pcLoaded = pointCloud('Lion.mat');

% Plot
pcLoaded.plot;

% Set three-dimensional view and add title
view(3); title('Point cloud loaded from mat file', 'Color', 'w');

 十、创建一个对象的副本,并选择其中的点子集

clc; clear; close; % clear everything

% Import point cloud
pc = pointCloud('Stone.ply'); % attributes from ply file are imported automatically

% Create an indipendent copy of the object
pcCopy = pc.copy;

% Select a subset of points and remove all non active points
pcCopy.select('UniformSampling', 40); % uniform sampling with mean sampling distance of 40 mm
pcCopy.reconstruct;

% Plot both point clouds
pc.plot('Color', 'y', 'MarkerSize', 1);
pcCopy.plot('Color', 'r', 'MarkerSize', 10);
view(3); title('Original point cloud (yellow) and filtered point cloud (red)', 'Color', 'w');

 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MATLAB中加载PLY格式的点云数据并拟合平面可以通过以下步骤实现。首先,确保已经安装了MATLAB的Computer Vision Toolbox。 1. 在MATLAB命令窗口中,使用pcread函数加载PLY格式的点云数据。例如,假设点云数据文件名为"pointcloud.ply",则可以使用以下代码加载数据: ```matlab ptCloud = pcread('pointcloud.ply'); ``` 2. 可以通过使用pcshow函数可视化加载的点云数据。例如,使用以下代码显示点云数据: ```matlab pcshow(ptCloud); ``` 此时会显示点云数据的三维可视化效果。 3. 接下来,我们可以使用pcfitplane函数拟合点云上的平面。该函数需要指定要拟合的点云数据和拟合平面时允许的最大距离(inlier distance tolerance)。指定的距离越大,拟合的平面越不精确。以下是一个示例代码: ```matlab [model, inlierIndices, outlierIndices] = pcfitplane(ptCloud, maxDistance); ``` 其中,model是拟合得到的平面模型,inlierIndices是平面上的的索引,outlierIndices是不在拟合平面上的的索引。 4. 可以使用pcshow函数将拟合的平面可视化。以下是一个示例代码: ```matlab pcshow(ptCloud.Location(inlierIndices,:), 'VerticalAxis', 'y', 'VerticalAxisDir', 'down'); hold on; plot(model); hold off; ``` 此时,会将点云数据和拟合的平面同时显示在一个坐标系中。 以上是用MATLAB加载PLY点云数据并拟合平面的简要步骤,根据具体情况可以进行更多自定义的操作和参数设置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值