Code covered by the BSD License  

Highlights from
MATLAB to Point Cloud Library

4.25

4.2 | 4 ratings Rate this file 92 Downloads (last 30 days) File Size: 7.24 KB File ID: #40382
image thumbnail

MATLAB to Point Cloud Library

by Peter Corke

 

19 Feb 2013 (Updated 14 Apr 2013)

matpcl is pure MATLAB code that allows interfacing with the Point Cloud Library (PCL) tools

| Watch this File

File Information
Description

matpcl is pure MATLAB code that allows interfacing with the Point Cloud Library (PCL) tools by reading and writing PCD format files. Being pure MATLAB avoids all kinds of headaches in trying to link PCL code into MEX files which involves various grief such as versions of compilers and support libraries such as boost.

There are only four user-level functions:

savepcd() writes a matrix as an optionally coloured point cloud in an ASCII PCD format file.

loadpcd() reads an optionally colored point cloud from a PCD format file (ASCII or binary) and returns a matrix.

pclviewer() writes a matrix to a temporary file and invokes the pcl_viewer app for visualization. This is much much faster for rotating a large point cloud than using a MATLAB 3D plot.

lscpd() shows the attributes of the PCD files in the current directory

Point clouds are considered to be either:

2-d matrices, with one column per point. The rows are X, Y, Z and for a colored point cloud X, Y, Z, R, G, B. (R,G,B) are in the range 0 to 1.

3-d matrices, with planes X, Y, Z and for a colored point cloud X, Y, Z, R, G, B. (R,G,B) are in the range 0 to 1.

Limitations (for now):

- No support for reading/writing normals

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Other requirements To run the viewer function pclviewer() you require an install of PCL. Edit pclviewer() to include the path to where your PCL binaries are installed, currently setup for MacOSX.
Tags for This File  
Everyone's Tags
data import, image processing, pcd, pcl, point cloud library
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
18 Jun 2013 Siddharth Choudhary

Hi Peter,

I get the error:

Index exceeds matrix dimensions.

Error in lzfd (line 59)
out(op:op+len-1) = out(ref:ref+len-1);

Error in loadpcd (line 188)
uncompressed_data = lzfd(compressed_data);

when I run loadpcd on a PCD file link: http://cogrob-dell-desktop.cc.gt.atl.ga.us/test.pcd

Can you check it?

Thanks,

11 Jun 2013 Peter Corke

Lauri, sorry to hear this is not working. I don't fully understand the lzfd logic, just transliterated it from another language and it worked ok on the compressed files I had. Can you share the file that caused the problem?

28 Apr 2013 Lauri

Hi,

lzfd.m (run by loadpcd.m) gives this error:

Index exceeds matrix dimensions.
Error in lzfd (line 59)
out(op:op+len-1) = out(ref:ref+len-1);

with this data (compressed binary): http://www.cs.tut.fi/~virtanel/skene2.pcd

Unfortunately I have no other datafiles to test nor time to debug lzfd myself.

19 Apr 2013 Daniel Wolf

Thanks a lot for your helpful work!
I think I've found a small bug in the loadpcd function processing RGB values. When you split the 4th field into RGB or RGBA values, everytime you shift the field value in the wrong direction using bitshift. Instead of bitshift(rgb, 16) it should be bitshift(rgb, -16) for a right shift instead of a left shift.

23 Mar 2013 Peter Corke

Thanks for the addition. regexp(... 'split') is a useful thing, I was looking for the equivalent of python's split() but didn't find this.

binary_compressed format next?

22 Mar 2013 Will

For the binary case, I've written some code to handle the rgb / rgba case. Please feel free to use / modify as needed. I hope this helps.

case 'binary'
startPos_fp = ftell(fp);
numFields = numel(siz);
typeTokens = regexp(type,'\s+','split');
fieldTokens = regexp(fields,'\s+','split');

% Just initialize the xyz portion for now
points = zeros(3, npoints);

for i=1:numFields
% map IUF -> int, uint, float
typeToken = typeTokens{i};
switch typeToken
case 'I'
fmt = 'int';
case 'U'
fmt = 'uint';
case 'F'
fmt = 'float';
end

format = ['*' fmt num2str(siz(i)*8)];
fseek(fp, startPos_fp + sum(siz(1:i-1)), 'bof');
data = fread(fp, [1 npoints], format, sum(siz)-siz(i));

fieldToken = fieldTokens{i};
switch fieldToken
case 'x'
points(1,:) = data;
case 'y'
points(2,:) = data;
case 'z'
points(3,:) = data;
case 'rgb'
rgb = typecast(data, 'uint32');
R = double(bitand(255, bitshift(rgb, 16))) /255;
G = double(bitand(255, bitshift(rgb, 8))) /255;
B = double(bitand(255, rgb)) /255;
points = [points(1:3,:); R; G; B];
case 'rgba'
rgb = typecast(data, 'uint32');
R = double(bitand(255, bitshift(rgb, 24))) /255;
G = double(bitand(255, bitshift(rgb, 16))) /255;
B = double(bitand(255, bitshift(rgb, 8))) /255;
A = double(bitand(255, rgb)) /255;
points = [points(1:3,:); R; G; B];
end
end

12 Mar 2013 Peter Corke

Thanks for pointing this out, I fixed the problem and uploaded a revised version of the code.

10 Mar 2013 Albert

First of all, thank you very much for the software. It is being very useful to me.

In addition, I want to comment you something. I've had a problem trying to run the software. Concretely, in loadpcd.m I was having an error related to the function "numcols" at the line 81. Matlab interpreter was complaining about it in such a way: "undefined function".

Well, I don't like to do this at all, but I changed "numcols(size)" by simply "length(size)" and I think it's working now.

Maybe the error is given by the fact that I'm in Matlab 2012a. As I see, you specified 2012b as your release.

Anyway, I just want to warn you.

Updates
22 Feb 2013

added logo image

11 Mar 2013

Removed references to function numcols() and replaced with the standard MATLAB function size(). Bad coding habit on my part...

25 Mar 2013

Now support organized point clouds. In MATLAB these are treated as 3D matrices with planes for X, Y, Z, etc.

Incorporated patch by Will.

Added lspcd() function to show attributes of PCD files in current directory.

14 Apr 2013

I've added some code to handle binary_compressed format, but it's not fully tested. To read these files requires LZF decoding, and so I had to write MATLAB code to do that (included as lzfd.m).

Contact us