Thursday 3 May 2012

matlab script on converting ply to pcd

PCL from willow garage is really useful for 3D geometric process and visualization, and it requires its own data format, say, point cloud data (pcd). In pcd file, the x, y, z coordinates are stored as float datatype, while color information rgb is packed into a 4 byte unsigned integer. I know it could use float to represent the rgb(a) information, unfortunately I did not make this work properly.

I wrote two matlab scripts to convert ply file generated by meshlab to pcd. One that I called as naive one, which scan each line in ply and then write them into pcd with appropriate format. The other one that I referred as efficient one due to data block can be read and written only once, it is about 10 times faster than the naive one for large file.

With respect to color conversion, as the color is stored as 8-bit unsigned integer for r, g, b channel in ply, while rgb is packed as  32-bit unsigned integer in pcd. I convert r, g, b from decimal to hex, and then pack them together and convert them back to decimal format. 

N.B.: currently it only supports the ply file with x,y,z or x,y,z, r,g,b information.
Download:

1 comment: