Artifacts when converting point clouds from double to float
This post was updated on .
I have a couple of LAS files containing large point clouds. In order to use them with the PCL I want to convert them to PCD. I wrote a simple Matlab script to do just that. The export works but I cannot visualize the point clouds in the pcl_viewer. When i read in the point cloud with it some random points appear for a split second and then the pcl_viewer is black.
I have traced to problem back the TYPE and SIZE of the data as specified in the PCD HEADER. My LAS file store the data as Doubles and the Matlab exporter also writes the files as Doubles by default. These files cannot be displayed in the pcl_viewer although they comply with the format specified here: http://pointclouds.org/documentation/tutorials/pcd_file_format.php . The header then reads: TYPE F F F and SIZE 8 8 8.
When I cast the data to float before exporting the data the header reads: TYPE F F F and SIZE 4 4 4. Also, the the coordinates' precision in the PCD file is reduced as well as the file size (as it should be). pcl_viewer can display the data now but the output looks strange (see screenshots).
The data are visualized here using the Matlab function pcshow() but the same problem occurs using the pcl_viewer. The reason why I use the Matlab function to show the data here is to demonstrate the difference between the exported DOUBLE and the exported FLOAT PCD files.
Double data type point cloud
Float data type point cloud:
Is this effect / artifact solely caused by loss of precision from double to float? Note that the float point cloud appears to have lines rather than single points.
BTW. I have also written a littel c++ programm using libLAS and PCL to do the same export thing. The results are the same when the data are converted to float which is a must when storing the data as pcl::PointXYZ. There is no PointXYZdouble as far as I know. Is that right?
Re: Artifacts when converting point clouds from double to float
This post was updated on .
Okay, so this is what i found out.
The bad quality point cloud is in fact caused by loss of precision due to conversion from double to float.
What I did to solve this is, I found out the MinX, MinY and MinZ values of the input point cloud and subtracted these values from all points for x,y,z, respectively. So the smallest value for each coordinate x,y,z will be 0 each. This saves many digits before the decimal point (in some cases as many as 7). And this way, there are more digits left behind the decimal point, therefore the loss of precision is reduced.
It is not a very nice solution but it its a simple work-around. There is still degradation in quality compared to the double type point cloud, however, this is acceptable.
I thought I share this in case someone runs into similar problems. Here is also the visual result for comparison.