File Exchange

image thumbnail

Point cloud tools for Matlab

version 2.0.0.0 (24.2 MB) by Philipp Glira
Various tools for working with large point clouds

55 Downloads

Updated 14 May 2020

GitHub view license on GitHub

Documentation: http://www.geo.tuwien.ac.at/downloads/pg/pctools/pctools.html
The point cloud tools currently include:
- pointCloud class: a Matlab class to read, manipulate and write point clouds
- globalICP class: a Matlab class to optimize the alignment of many point clouds with the ICP algorithm

Installation:
1. Download package
2. Add the downloaded folder to the search path in Matlab:
addpath(genpath('D:\MyMatlabCode\pointCloudTools'));
3. Finally, check if it is working by running:
pc = pointCloud('Lion.xyz');
pc.plot;

Cite As

Philipp Glira (2020). Point cloud tools for Matlab (https://github.com/pglira/Point_cloud_tools_for_Matlab), GitHub. Retrieved .

Comments and Ratings (72)

Gemma

I'm not sure if the logfile I got is what you want to see. So I've emailed you the code and data I used. Thank you so much!

Philipp Glira

Hi Jiaxing, can you send me the full logfile in debug mode (i.e. calling runICP with 'LogLevel', 'debug')? My mail adress is philipp.glira@ait.ac.at

Hi, Philipp,
I was trying to use this tool to registration several points clouds from roadside laser scanning system. The file format is .csv. I got the following errors when I implemented the command runICP as follows:
<img width="434" alt="3" src="https://user-images.githubusercontent.com/35533389/82749670-b7ac3300-9da2-11ea-905d-31a32185bfa5.png">

<img width="772" alt="1" src="https://user-images.githubusercontent.com/35533389/82749664-afec8e80-9da2-11ea-8989-7562cf7195b0.png">
<img width="363" alt="2" src="https://user-images.githubusercontent.com/35533389/82749665-afec8e80-9da2-11ea-9016-62e3ecac4e33.png">

I tried to adjust the parameter "UniformSamplingDistance" to different values, and I still got similar errors.

Can you please give me some clues? Thanks a lot

Philipp Glira

Hi Mikhail, exactly, the code needs to be included with:
addpath(genpath('path-to-m-files'));

Hi Philipp

After several tests I discovered that it is necessary to add path not only to the folder with your code but also to all subfolders. After this step you code start working amazing.

Thanks a lot

Philipp Glira

Hi Oling, the pointCloud class from the Computer Vision Toolbox is used instead of my class. Unfortunately they have the same name (the one in the CV Toolbox was introduced later). Please include the path to my pointCloud class at the top of the Matlab path. It should work then.

oling

Hi Philipp,
I got an error trying to do the first example.

pc=pointCloud('Lion.xyz');
Error using
pointclouds.internal.pc.pointCloudImpl>validateAndParseInputs
(line 1559)
The value of 'xyzPoints' is invalid. Expected input to
be one of these types:

single, double

Error in pointclouds.internal.pc.pointCloudImpl (line
73)
[xyzPoints, C, nv, I] =
validateAndParseInputs(varargin{:});

Error in pointCloud (line 109)
this =
this@pointclouds.internal.pc.pointCloudImpl(varargin{:});

Hi Philipp I sended e-mail. Thank you ..

Philipp Glira

Hi Pelinsu, send me an email with the data and the code and I will check it.

Hi Philipp , when I use "normals" function I get error message like "Index in position 2 exceeds array bounds (must not exceed 1)." . And also for some points 2. and 3. cells come out empty . Just 1. lamba value calculated for some points.

And also this error : "Error in @(x)x(:,3)".

Thank you..

Philipp Glira

Hi Pelinsu, you can have a look at the code in pointCloud.normals (simply run edit pointCloud.normals in Matlab). You will see that a principal component analysis (PCA) is used to estimate the normal vector and the according roughness value. A more comprehensive description can be found in [1], chapter 4. Hope this helps.
[1] https://www.ingentaconnect.com/content/schweiz/pfg/2015/00002015/00000004/art00001

Hi Philipp, first of all, thank you very much for the point cloud tool you shared. It was very helpful for my graduation project. In my project using the pc.normals () function you wrote, I extract the roof points with the help of roughness values. But I need to explain mathematically every function I use while writing my report.If you ask, can you give me a document, an article or an auxiliary resource about how the function calculates the normals? I need to understand exactly how the pc.normals () function works and explain it in my report.I hope you can help. Thanks , have a good day..

Thank you so much, now I can visualize my point cloud. Best regards

Philipp Glira

Hi Marina, you can find a documentation of the supported files with "help pointCloud.pointCloud". The simplest format is a plain text file (e.g. with file extension xyz) which contains on each line the three coordinates x y z of a single point. Simply genarte such a file for your point cloud and try to read it with pc = pointCloud(my-pointcloud-file.txt);. If that doesn't help, please send me your file by e-mail so that I can have a look at it.

Hi Philipp, Thanks you for your amazing work!
I would ask you about an issue I have with my pointCloud file. The problem I have is that I have a point cloud in another format than your lion for example. I have been trying to create a new point cloud with my data in your format but it does not work. How can I create a point cloud from scratch compatible with your library? Both your lion and my point cloud are the same type of data "point cloud" but the property inspector shows different things. In fact, if I load my point cloud and then, I add the path to use your library, the properties of my point cloud are empty.
Thanks a lot for your help.

MoHa

Hi Philipp, Amazing Function!
I'm just trying to compare two point clouds (or mesh to cloud) and show the distance between them as a color map without registration. Is there any possibility to do this?
I would be grateful for your answer, help, ideas or suggestions.

Philipp Glira

Hi Gabriela, it seems that the file "plot_start.m" can not be found on your matlab path. However, it is included in the package:

https://github.com/pglira/Point_cloud_tools_for_Matlab/blob/master/classes/4pointCloud/4plot/plot_start.m

Try to include the whole package with addpath(genpath(<path-to-the-downloaded-package>));

The same applies to the non-found "select.m" file which is also included in the package.

Hello Philipp, I am trying to run the sample code for the simultaneous alignment of six point clouds. However, when I run the code I get an error that says:
Undefined function or variable 'plot_start'.

Error in pointCloud/plot (line 72)
[hFig, idxPC, firstCall] = plot_start;

Error in globalICP/plot (line 28)
pc.plot(varargin{:});

This function is not defined nor is there a .m file in the functions folder.

I had a similar issue running runICP as uniformSampling is not defined in the pointCloud -> select.m file either. I would appreciate your help. thank you.

Hi Ehsan, the problem is that the pointCloud class from the ComputerVision Toolbox is used. Unfortunately they have the same name. Please include the path to my pointCloud class at the top of the Matlab path. It should work then.

Hi Philipp, Thank you so much for you tools. I need some help. Because I can't read the xyz.file.
I try to run this code: pc = pointCloud('Lion.xyz');

But I see such an error:

Error using pointCloud>validateAndParseInputs (line 775)
The value of 'xyzPoints' is invalid. Expected input to be one of these types:

single, double

Instead its type was char.

Error in pointCloud (line 126)
[xyzPoints, C, nv] = validateAndParseInputs(varargin{:});

I don't know how to fix this =(

Philipp Glira

It should work this way:
icp = globalICP('OutputFolder', ...);
icp.addPC(scan_pcl, 'Label', 'moving');
You can find my mail address in the source code or on the documentation page.

Error in pcread (line 287)
p.pcData contains not only the points but all properties so line X = p.pcData(:,1:3) fails. What also makes me wondering is that the pointCloud does not contain normals... Aren't they necessary or will they be computed later on?

Thanks. How can I send you?
What I wrote yesterday is actually not true. I start with a n x 3 Matrix and use

moving = pointCloud(scan_pcl, 'Label', 'moving');
after that i do
icp = globalICP('OutputFolder', ...);
and
icp.addPC(moving);

Best Regards

Philipp Glira

Hi Nikolai, there seems to be an issue with the import of the point cloud. Which file format are you using? If you send me a single point cloud file, I could have a look at it.

Hi Phillip,
i try to make your tool work... but have a strange error when using icp.addPC(nx3 Matrix):

Index in position 2 exceeds array bounds (must not exceed 1).
Error in pcread (line 287)
X = p.pcData(:,1:3); % points (takes no time -> pass by reference)
Error in pointCloud (line 227)
[XNonRed, A] = pcread(p.pcData, 'Attributes' , p.Attributes, ...
Error in globalICP/addPC (line 48)
objPC = pointCloud(varargin{:});
Error in registration (line 70)
icp.addPC(moving);

Would be nice to get some help :)

Hi Gaetano, I'm sorry, the pointCloud class currently offers no segmentation algorithm.

Hi Philipp, thanks for your answer.
I saw you have different ways to select region of points, but there is anything to perform geometric segmentation? I would need to identify a plane with some cylinder on his surface

Hi Gaetano, no, unfortunately the point clouds need to have approximately the same scale before matching them with the ICP algorithm. A scale factor can be estimated using 'NoOfTransfParam', 7 (similarity transformation), but it should not differ significantly from 1.

Hi Phillipp, does your tool support scaled icp to match 2 point cloud of different scale?

lei deng

Mohsin Shah

Philipp, thank you a lot! This answered my question.

Philipp Glira

If I rightly understand, you need the transformation matrices for each individual iteration. You can access the homogeneous representation of these transformation matrices after completion of the ICP algorithm trough icp.D.dH.

For instance icp.D.dH{2,3} is the transformation matrix of point cloud no. 3 in the 2rd iteration.

Attention: These matrices relate to the reduction point if you are using one (parameter RedPoi when importing the point clouds).

For the sake of completeness: the final transformation matrices (i.e. for transformation of the original point cloud to its final state) can be accessed by
1) icp.D.H (relate to reduction point)
2) icp.D.HO (do not relate to reduction point, i.e. can be applied to original coordinates)

Philipp, your code is great! It makes the point cloud processing quite effortlessly. A question: for the point cloud alignment (globalICP.runICP()), is there an easy way of getting the transformation matrix that is applied to each point cloud? The ICP function in the following can do it by comparing the point clouds before and after alignment, but it seems double efforts: https://www.mathworks.com/matlabcentral/fileexchange/27804-iterative-closest-point . Since you have already done the ICP, there should be easy to obtain the transformation matrices during the iteration, right?

Bin zhang

The function 'MSG' that corresponds to the input parameter of the 'cell' type is not defined.
error: pointCloud (line 218)
msg('S', procHierarchy);

Juhyun Pyo

The problem solved by substituting 'by PC' for plot3 color value.
Thanks,

Hi Philipp,
Thank you for sharing the toolbox.
when I run the example in the documentation for globalICP (Minimal working example with 6 point clouds), I get the following error. May help me with that? I think the problem is because of using 'random' as the plot3 color.
Thanks,

Error using plot3
Specified character vector is an invalid color value.
Error in plot_updatePlot (line 140)
PC.U.hPlot = plot3(hAxes, PC.X(act4plot,1), PC.X(act4plot,2),
PC.X(act4plot,3), '.', 'MarkerSize', PC.U.p.MarkerSize, 'Color',
PC.U.p.Color);
Error in plot_setPrmAndPlot (line 101)
plot_updatePlot(hFig, idxPC);
Error in pointCloud/plot (line 97)
plot_setPrmAndPlot(hFig, idxPC, varargin{:})
Error in globalICP/plot (line 28)
pc.plot(varargin{:});

Philipp Glira

Hi, unfortunately the number of iterations defined by the parameter 'MaxNoIt' is currently fixed. It's on my todo list to implement an automatic stop based on some kind of convergence criteria.

Thank you for your excellent code. It works very well.
But I need a small help on runICP, I wonder if I set a large number of ICP iterations, how can it stop automatically when the accuracy requirement is met?

ok, found the solution to the problem. All works, huge thanks!

Hey Philipp, could you say, what may be the problem here?

Error using ~=
Too many input arguments.

Error in runICPVoxelHulls (line 14)
if any(PC{i}.redPoi ~= obj.D.redPoi)

Error in globalICP/runICP (line 202)
[obj, g, VH] = runICPVoxelHulls(obj, p, g, PC);

Error in Untitled (line 39)
icp.runICP(ICPOptions);

Philipp Glira

Hi Rash, the solution should be:
pc = pointCloud('Lion.xyz');
[minZ, idxMinZ] = min(pc.X(:,3));
minX = pc.X(idxMinZ,1);
minY = pc.X(idxMinZ,2);

Rash Sal

Thankyou philip, it works great, i need a small help on a point cloud of a face, for the three coordinates i want to know the coordinates of x and y for min(z), but could not find any help, can you guide please?

An Ku

medo ali

how can run globalICP class
the plot that display ICP iteration and std, main ,...
i get this error
The class globalICP has no Constant property or Static method named 'private'.
how can i solve it ?

Sheon yan

hbabar

Okay I think this maybe a more upto date version of the maltab pointCloud class, because it has a few extra functions than the ones that came with R2017a. Am I right ? In that case would there be some sort of a clash if i install this one ? Because soem functions would be listed in both.

hbabar

Hi, I wanted to know what is the difference between your class and the pointCloud class already in matlab(in the Computer Vision System Toolbox). Are they the same ?

Philipp Glira

Great! You can find the related papers on the documentation website (http://www.geo.tuwien.ac.at/downloads/pg/pctools/pctools.html ) for citations. Thanks.

Thanks Philipp. It works. Last question. Tell me how can I cite this work.

Philipp Glira

Hi Grigor, you can save the selected points on the command line with:
hFig = gcf;
X = hFig.UserData.PC{1}.X(hFig.UserData.PC{1}.act,:);
Hope this helps.

Hi Philipp, thanks for the answer. I tried selecting some points from the window and then write on command line X = pc.X(pc.act,:); but the new variable X gives me again the full point cloud.

Hi Grigor, you can save the selected point coordinates with X = pc.X(pc.act,:);

Hi Philipp,
I am using your toolbox to select points using the 'profile mode'. Then I further elaborate the exported (selected) points with a code I wrote. Currently I am using it from command line in matlab as:

lineStart = [0.75 -0.75];
lineEnd = [4 -4];
lineWidth = 0.4;
az = pc.select('Profile', lineStart, lineEnd, lineWidth);
close; pc.plot('MarkerSize', 5);
title('Profile', 'Color', 'w'); view(az,0);
pc.export('9.6_O_NW_315.ply');

Because I have to repeat the operation many times, I was wondering if there is a way to have the selected points through the user-interface window saved as variable (coordinates). Thanks

Philipp Glira

Hi Anwar, generation and manipulation of meshes can't be done with this code here, but you may find this useful: http://iso2mesh.sourceforge.net

Hi Philipp
i want to fill the holes on my 3D model may please suggest me any command or any code that help me to fill my mesh to be a full 3D model...
thank you

Philipp Glira

Hi Rash,

line 196 of pointCloud.m is
[~, ~, ext] = fileparts(path2pointCloud);
If your file exists, there should be no problem.

How did you call pointCloud(...)?

You can also contact me also by mail (see documentation or m-files).

Rash Sal

??? Error using ==> pointCloud
Error: File: pointCloud.m Line: 196 Column: 15
help please

Philipp Glira

Hi Zulfadhli!

Did you use ICP.m or ICP.exe? I made some updates to the code right now, please tell me if this minimal example for ICP.exe is working now:

ICP -inFiles demodata/lionscan*approx.xyz -UniformSamplingDistance 2 -PlaneSearchRadius 2 -Plot 1

You can find the data in the "demodata" folder.

Please also note that the code is hosted on GitHub and is updated here only once a day. So if you want to test the updated code today, you have to download it directly on GitHub.

Hello. I faced an error to run.

Undefined function or variable 'p'.

Error in ICP (line 258)
pp.parse(p.ICP);

Can anyone please help?

be honest, because of my own reasons, I did not succeed in your Toolbox. First, suggesting that I don't have enough memory, which is wrong. Eg:Error using pointCloud'has to be a top level statement', I did not understand what this means.

Philipp Glira

Hi Fnya, I tested the example right now on my computer and it is working fine. Is this error reproducible? You can also contact me by mail (see documentation or m-files).

Fnya

Hello!

I tested the SIMULTANEOUS ALIGNMENT OF THREE TLS POINT CLOUDS and I got error saying:

`Error using copyfile
No matching files were found.

Error in runICPTransformFinal (line 25)
copyfile(obj.PC{i}, p2mat);

Error in globalICP/runICP (line 259)
obj = runICPTransformFinal(obj, p, g);

Error in script_TLS (line 17)
icp = icp.runICP(ICPOptions);`

Need help please.

Ralph L

Hello Philipp !

I've used your Toolbox and have been amazed by its capacities !

Thank you so much !

Lipeng Jiu

Updates

2.0.0.0

Major update for pointCloud and globalICP class.

1.0.0.0

Tags added

1.0.0.0

Image updated

1.0.0.0

Image updated

1.0.0.0

Image added

1.0.0.0

Description updated

1.0.0.0

Description updated

1.0.0.0

Description updatet

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

classes/4lsAdj

classes/4pointCloud

classes/4pointCloud/4plot

classes/@corrPoints

classes/@globalICP

classes/@globalICP/private

classes/@img

classes/@lsAdj

classes/@pointCloud

classes/@polyMesh

costfunctions

external/export_fig

functions

scripts