当前位置: 首页 > article >正文

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');

 


http://www.kler.cn/a/14550.html

相关文章:

  • Springboot 自动装配流程分析
  • 代码随想录算法训练营第三十九天|62.不同路径、63. 不同路径 II
  • SQLite数据库简单小入门学习(二)
  • 谁是液冷行业真龙头?疯狂的液冷技术!
  • Linux Shell 实现一键部署http+用户名密码登录
  • 1.13|1.14|1.15|1.6、GDB调试
  • LiangGaRy_学习笔记_Day01
  • 聊聊 maven的版本号version 以及maven指定版本号范围写法
  • 【Chatgpt4 教学】 NLP(自然语言处理)第九课 朴素贝叶斯分类器的工作原理 机器学习算法
  • 纳芯微携手企企通,打造全新数字化采购管理系统
  • C++设计模式之备忘录模式
  • Microsoft Defender for Office 365部署方案
  • 湿法冶金铼提取工艺
  • sqoop安装
  • AI 编程
  • MySQL数据类型
  • 1.10和1.11和1.12、Makefile
  • ADKEY多按键制作阻值选择
  • OpenJudge - 39:多项式输出
  • Jenkins+Python自动化测试持续集成详细教程(全网独家)