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

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.lryc.cn/news/61198.html

相关文章:

  • 反射-Class类分析
  • Let’s Make C++ Great Again——string与常用字符处理函数
  • 〖Python网络爬虫实战⑰〗- 网页解析利器parsel实战
  • 中电金信:生成式AI热潮下,文本智能走向何方?
  • 探索Linux设备树:硬件描述与驱动程序的桥梁
  • UNION ALL用法 以及 UNION ALL和UNION的区别
  • Ubuntu Linux操作
  • MongoDB常用语句(CURD)
  • 一篇文章让你彻底学会--节流(并且自己可以手写)
  • C++ 形参是类的指针 class * 通过new的方式创建对象
  • 手把手教你将项目部署到服务器!
  • OpenHarmony应用开发-ArkUI方舟开发框架简析
  • 【Transformer系列(4)】Transformer模型结构超详细解读
  • Idea启动运行报错:Error:java: 无效的源发行版: 13
  • 【元分析研究方法】学习笔记1.形成问题
  • 2023年3月 青少年软件编程(Python) 等级考试试卷(五级)
  • 必须要知道的hive调优知识(上)
  • 什么是Cache Aside Pattern与延迟双删
  • frp 流量特征
  • Unity --- UGUI(Unity Graphical user interface)--- Canvas画布
  • c++积累6-内联函数
  • ESP32学习笔记13-MCPWM主要用于无刷电机驱动
  • MyBatis-plu 和 JPA 对比
  • 一文详解Python中多进程和进程池的使用方法
  • 前端部署发布项目后,如何通知用户刷新页面、清除缓存
  • 项目上线|慕尚集团携手盖雅工场,用数字化推动人效持续提升
  • Java重载 与封装、继承
  • sed正则表达式替换字符方法
  • 不讲废话普通人了解 ChatGPT——基础篇第一课
  • MATLAB计算气象干旱指标:SAPEI